Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved. | 2 * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 , m_name(name) | 42 , m_name(name) |
| 43 { | 43 { |
| 44 ScriptWrappable::init(this); | 44 ScriptWrappable::init(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 RadioNodeList::~RadioNodeList() | 47 RadioNodeList::~RadioNodeList() |
| 48 { | 48 { |
| 49 ownerNode()->nodeLists()->removeCacheWithAtomicName(this, RadioNodeListType, m_name); | 49 ownerNode()->nodeLists()->removeCacheWithAtomicName(this, RadioNodeListType, m_name); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static inline HTMLInputElement* toRadioButtonInputElement(Node* node) | 52 static inline Result<HTMLInputElement> toRadioButtonInputElement(Node* node) |
| 53 { | 53 { |
| 54 ASSERT(node->isElementNode()); | 54 ASSERT(node->isElementNode()); |
| 55 HTMLInputElement* inputElement = node->toInputElement(); | 55 Handle<HTMLInputElement> inputElement = node->toInputElement(); |
| 56 if (!inputElement || !inputElement->isRadioButton() || inputElement->value() .isEmpty()) | 56 if (!inputElement || !inputElement->isRadioButton() || inputElement->value() .isEmpty()) |
| 57 return 0; | 57 return nullptr; |
| 58 return inputElement; | 58 return inputElement; |
| 59 } | 59 } |
| 60 | 60 |
| 61 String RadioNodeList::value() const | 61 String RadioNodeList::value() const |
| 62 { | 62 { |
| 63 for (unsigned i = 0; i < length(); ++i) { | 63 for (unsigned i = 0; i < length(); ++i) { |
| 64 Node* node = item(i); | 64 Node* node = item(i); |
| 65 const HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 65 Handle<const HTMLInputElement> inputElement = toRadioButtonInputElement( node); |
|
Vyacheslav Egorov (Google)
2013/07/18 16:50:08
HandleScope?
haraken
2013/07/19 02:57:09
Done.
| |
| 66 if (!inputElement || !inputElement->checked()) | 66 if (!inputElement || !inputElement->checked()) |
| 67 continue; | 67 continue; |
| 68 return inputElement->value(); | 68 return inputElement->value(); |
| 69 } | 69 } |
| 70 return String(); | 70 return String(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void RadioNodeList::setValue(const String& value) | 73 void RadioNodeList::setValue(const String& value) |
| 74 { | 74 { |
| 75 for (unsigned i = 0; i < length(); ++i) { | 75 for (unsigned i = 0; i < length(); ++i) { |
| 76 Node* node = item(i); | 76 Node* node = item(i); |
| 77 HTMLInputElement* inputElement = toRadioButtonInputElement(node); | 77 Handle<HTMLInputElement> inputElement = toRadioButtonInputElement(node); |
|
Vyacheslav Egorov (Google)
2013/07/18 16:50:08
HandleScope? (ditto in other loops).
haraken
2013/07/19 02:57:09
Done.
| |
| 78 if (!inputElement || inputElement->value() != value) | 78 if (!inputElement || inputElement->value() != value) |
| 79 continue; | 79 continue; |
| 80 inputElement->setChecked(true); | 80 inputElement->setChecked(true); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(Element* testElement) const | 85 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(Element* testElement) const |
| 86 { | 86 { |
| 87 ASSERT(testElement->hasTagName(objectTag) || testElement->isFormControlEleme nt()); | 87 ASSERT(testElement->hasTagName(objectTag) || testElement->isFormControlEleme nt()); |
| 88 if (ownerNode()->hasTagName(formTag)) { | 88 if (ownerNode()->hasTagName(formTag)) { |
| 89 HTMLFormElement* formElement = 0; | 89 HTMLFormElement* formElement = 0; |
| 90 if (testElement->hasTagName(objectTag)) | 90 if (testElement->hasTagName(objectTag)) |
| 91 formElement = static_cast<HTMLObjectElement*>(testElement)->form(); | 91 formElement = static_cast<HTMLObjectElement*>(testElement)->form(); |
| 92 else | 92 else |
| 93 formElement = static_cast<HTMLFormControlElement*>(testElement)->for m(); | 93 formElement = static_cast<HTMLFormControlElement*>(testElement)->for m(); |
| 94 if (!formElement || formElement != ownerNode()) | 94 if (!formElement || formElement != ownerNode()) |
| 95 return false; | 95 return false; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return testElement->getIdAttribute() == m_name || testElement->getNameAttrib ute() == m_name; | 98 return testElement->getIdAttribute() == m_name || testElement->getNameAttrib ute() == m_name; |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool RadioNodeList::nodeMatches(Element* testElement) const | 101 bool RadioNodeList::nodeMatches(Element* testElement) const |
| 102 { | 102 { |
| 103 if (!testElement->hasTagName(objectTag) && !testElement->isFormControlElemen t()) | 103 if (!testElement->hasTagName(objectTag) && !testElement->isFormControlElemen t()) |
| 104 return false; | 104 return false; |
| 105 | 105 |
| 106 if (HTMLInputElement* inputElement = testElement->toInputElement()) { | 106 if (Handle<HTMLInputElement> inputElement = testElement->toInputElement()) { |
| 107 if (inputElement->isImageButton()) | 107 if (inputElement->isImageButton()) |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 return checkElementMatchesRadioNodeListFilter(testElement); | 111 return checkElementMatchesRadioNodeListFilter(testElement); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namspace | 114 } // namspace |
| 115 | 115 |
| OLD | NEW |