Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: Source/core/html/RadioNodeList.cpp

Issue 331863003: Have NodeList::item() overrides return an Element* when appropriate (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/NamedNodesCollection.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 ScriptWrappable::init(this); 45 ScriptWrappable::init(this);
46 } 46 }
47 47
48 RadioNodeList::~RadioNodeList() 48 RadioNodeList::~RadioNodeList()
49 { 49 {
50 #if !ENABLE(OILPAN) 50 #if !ENABLE(OILPAN)
51 ownerNode().nodeLists()->removeCache(this, m_onlyMatchImgElements ? RadioImg NodeListType : RadioNodeListType, m_name); 51 ownerNode().nodeLists()->removeCache(this, m_onlyMatchImgElements ? RadioImg NodeListType : RadioNodeListType, m_name);
52 #endif 52 #endif
53 } 53 }
54 54
55 static inline HTMLInputElement* toRadioButtonInputElement(Node& node) 55 static inline HTMLInputElement* toRadioButtonInputElement(Element& element)
56 { 56 {
57 ASSERT(node.isElementNode()); 57 if (!isHTMLInputElement(element))
58 if (!isHTMLInputElement(node))
59 return 0; 58 return 0;
60 HTMLInputElement& inputElement = toHTMLInputElement(node); 59 HTMLInputElement& inputElement = toHTMLInputElement(element);
61 if (!inputElement.isRadioButton() || inputElement.value().isEmpty()) 60 if (!inputElement.isRadioButton() || inputElement.value().isEmpty())
62 return 0; 61 return 0;
63 return &inputElement; 62 return &inputElement;
64 } 63 }
65 64
66 String RadioNodeList::value() const 65 String RadioNodeList::value() const
67 { 66 {
68 if (m_onlyMatchImgElements) 67 if (m_onlyMatchImgElements)
69 return String(); 68 return String();
70 for (unsigned i = 0; i < length(); ++i) { 69 unsigned length = this->length();
71 Node* node = item(i); 70 for (unsigned i = 0; i < length; ++i) {
72 const HTMLInputElement* inputElement = toRadioButtonInputElement(*node); 71 const HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i ));
73 if (!inputElement || !inputElement->checked()) 72 if (!inputElement || !inputElement->checked())
74 continue; 73 continue;
75 return inputElement->value(); 74 return inputElement->value();
76 } 75 }
77 return String(); 76 return String();
78 } 77 }
79 78
80 void RadioNodeList::setValue(const String& value) 79 void RadioNodeList::setValue(const String& value)
81 { 80 {
82 if (m_onlyMatchImgElements) 81 if (m_onlyMatchImgElements)
83 return; 82 return;
84 for (unsigned i = 0; i < length(); ++i) { 83 unsigned length = this->length();
85 Node* node = item(i); 84 for (unsigned i = 0; i < length; ++i) {
86 HTMLInputElement* inputElement = toRadioButtonInputElement(*node); 85 HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
87 if (!inputElement || inputElement->value() != value) 86 if (!inputElement || inputElement->value() != value)
88 continue; 87 continue;
89 inputElement->setChecked(true); 88 inputElement->setChecked(true);
90 return; 89 return;
91 } 90 }
92 } 91 }
93 92
94 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl ement) const 93 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl ement) const
95 { 94 {
96 ASSERT(!m_onlyMatchImgElements); 95 ASSERT(!m_onlyMatchImgElements);
(...skipping 16 matching lines...) Expand all
113 return false; 112 return false;
114 113
115 if (isHTMLInputElement(element) && toHTMLInputElement(element).isImageButton ()) 114 if (isHTMLInputElement(element) && toHTMLInputElement(element).isImageButton ())
116 return false; 115 return false;
117 116
118 return checkElementMatchesRadioNodeListFilter(element); 117 return checkElementMatchesRadioNodeListFilter(element);
119 } 118 }
120 119
121 } // namespace 120 } // namespace
122 121
OLDNEW
« no previous file with comments | « Source/core/dom/NamedNodesCollection.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698