Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
| 10 * | 10 * |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 setSelectedIndex(optionIndex); | 246 setSelectedIndex(optionIndex); |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 optionIndex++; | 249 optionIndex++; |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 setSelectedIndex(-1); | 253 setSelectedIndex(-1); |
| 254 } | 254 } |
| 255 | 255 |
| 256 String HTMLSelectElement::suggestedValue() const | |
| 257 { | |
| 258 const Vector<HTMLElement*>& items = listItems(); | |
| 259 for (unsigned i = 0; i < items.size(); i++) { | |
|
tkent
2014/03/14 00:06:41
We prefer ++i.
ziran.sun
2014/03/14 11:32:37
Done.
| |
| 260 if (items[i]->hasLocalName(optionTag) && toHTMLOptionElement(items[i])-> value() == m_suggestedValue) | |
| 261 return m_suggestedValue; | |
| 262 } | |
| 263 return ""; | |
| 264 } | |
| 265 | |
| 266 void HTMLSelectElement::setSuggestedValue(const String& value) | |
| 267 { | |
| 268 m_suggestedValue = value; | |
| 269 | |
| 270 if (value.isNull()) { | |
| 271 setSuggestedIndex(-1); | |
| 272 return; | |
| 273 } | |
| 274 | |
| 275 const Vector<HTMLElement*>& items = listItems(); | |
| 276 unsigned optionIndex = 0; | |
| 277 for (unsigned i = 0; i < items.size(); i++) { | |
|
tkent
2014/03/14 00:06:41
Ditto.
ziran.sun
2014/03/14 11:32:37
Done.
| |
| 278 if (items[i]->hasLocalName(optionTag)) { | |
| 279 if (toHTMLOptionElement(items[i])->value() == value) { | |
| 280 setSuggestedIndex(optionIndex); | |
| 281 return; | |
| 282 } | |
| 283 optionIndex++; | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 setSuggestedIndex(-1); | |
| 288 } | |
| 289 | |
| 256 bool HTMLSelectElement::isPresentationAttribute(const QualifiedName& name) const | 290 bool HTMLSelectElement::isPresentationAttribute(const QualifiedName& name) const |
| 257 { | 291 { |
| 258 if (name == alignAttr) { | 292 if (name == alignAttr) { |
| 259 // Don't map 'align' attribute. This matches what Firefox, Opera and IE do. | 293 // Don't map 'align' attribute. This matches what Firefox, Opera and IE do. |
| 260 // See http://bugs.webkit.org/show_bug.cgi?id=12072 | 294 // See http://bugs.webkit.org/show_bug.cgi?id=12072 |
| 261 return false; | 295 return false; |
| 262 } | 296 } |
| 263 | 297 |
| 264 return HTMLFormControlElementWithState::isPresentationAttribute(name); | 298 return HTMLFormControlElementWithState::isPresentationAttribute(name); |
| 265 } | 299 } |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 } | 822 } |
| 789 | 823 |
| 790 return -1; | 824 return -1; |
| 791 } | 825 } |
| 792 | 826 |
| 793 void HTMLSelectElement::setSelectedIndex(int index) | 827 void HTMLSelectElement::setSelectedIndex(int index) |
| 794 { | 828 { |
| 795 selectOption(index, DeselectOtherOptions); | 829 selectOption(index, DeselectOtherOptions); |
| 796 } | 830 } |
| 797 | 831 |
| 832 int HTMLSelectElement::suggestedIndex() const | |
| 833 { | |
| 834 return m_suggestedIndex; | |
| 835 } | |
| 836 | |
| 837 void HTMLSelectElement::setSuggestedIndex(int suggestedIndex) | |
| 838 { | |
| 839 m_suggestedIndex = suggestedIndex; | |
| 840 | |
| 841 if (RenderObject* renderer = this->renderer()) { | |
| 842 renderer->updateFromElement(); | |
| 843 if (renderer->isListBox()) | |
| 844 toRenderListBox(renderer)->scrollToRevealElementAtListIndex(suggeste dIndex); | |
| 845 } | |
| 846 | |
| 847 setNeedsValidityCheck(); | |
|
tkent
2014/03/14 00:06:41
I don't think validity check is necessary. Updatin
ziran.sun
2014/03/14 11:32:37
Done.
| |
| 848 } | |
| 849 | |
| 798 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected) | 850 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected) |
| 799 { | 851 { |
| 800 ASSERT(option->ownerSelectElement() == this); | 852 ASSERT(option->ownerSelectElement() == this); |
| 801 if (optionIsSelected) | 853 if (optionIsSelected) |
| 802 selectOption(option->index()); | 854 selectOption(option->index()); |
| 803 else if (!usesMenuList() || multiple()) | 855 else if (!usesMenuList() || multiple()) |
| 804 selectOption(-1); | 856 selectOption(-1); |
| 805 else | 857 else |
| 806 selectOption(nextSelectableListIndex(-1)); | 858 selectOption(nextSelectableListIndex(-1)); |
| 807 } | 859 } |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1564 { | 1616 { |
| 1565 return true; | 1617 return true; |
| 1566 } | 1618 } |
| 1567 | 1619 |
| 1568 bool HTMLSelectElement::supportsAutofocus() const | 1620 bool HTMLSelectElement::supportsAutofocus() const |
| 1569 { | 1621 { |
| 1570 return true; | 1622 return true; |
| 1571 } | 1623 } |
| 1572 | 1624 |
| 1573 } // namespace | 1625 } // namespace |
| OLD | NEW |