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

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

Issue 480473002: Drop unnecessary RadioNodeList::m_onlyMatchImgElements member (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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/html/RadioNodeList.h ('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 22 matching lines...) Expand all
33 #include "core/html/HTMLInputElement.h" 33 #include "core/html/HTMLInputElement.h"
34 #include "core/html/HTMLObjectElement.h" 34 #include "core/html/HTMLObjectElement.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 using namespace HTMLNames; 38 using namespace HTMLNames;
39 39
40 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name, CollectionType type) 40 RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name, CollectionType type)
41 : LiveNodeList(rootNode, type, InvalidateForFormControls, isHTMLFormElement( rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode) 41 : LiveNodeList(rootNode, type, InvalidateForFormControls, isHTMLFormElement( rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
42 , m_name(name) 42 , m_name(name)
43 , m_onlyMatchImgElements(type == RadioImgNodeListType)
44 { 43 {
45 ScriptWrappable::init(this); 44 ScriptWrappable::init(this);
46 } 45 }
47 46
48 RadioNodeList::~RadioNodeList() 47 RadioNodeList::~RadioNodeList()
49 { 48 {
50 #if !ENABLE(OILPAN) 49 #if !ENABLE(OILPAN)
51 ownerNode().nodeLists()->removeCache(this, m_onlyMatchImgElements ? RadioImg NodeListType : RadioNodeListType, m_name); 50 ownerNode().nodeLists()->removeCache(this, type(), m_name);
52 #endif 51 #endif
53 } 52 }
54 53
55 static inline HTMLInputElement* toRadioButtonInputElement(Element& element) 54 static inline HTMLInputElement* toRadioButtonInputElement(Element& element)
56 { 55 {
57 if (!isHTMLInputElement(element)) 56 if (!isHTMLInputElement(element))
58 return 0; 57 return 0;
59 HTMLInputElement& inputElement = toHTMLInputElement(element); 58 HTMLInputElement& inputElement = toHTMLInputElement(element);
60 if (!inputElement.isRadioButton() || inputElement.value().isEmpty()) 59 if (!inputElement.isRadioButton() || inputElement.value().isEmpty())
61 return 0; 60 return 0;
62 return &inputElement; 61 return &inputElement;
63 } 62 }
64 63
65 String RadioNodeList::value() const 64 String RadioNodeList::value() const
66 { 65 {
67 if (m_onlyMatchImgElements) 66 if (shouldOnlyMatchImgElements())
68 return String(); 67 return String();
69 unsigned length = this->length(); 68 unsigned length = this->length();
70 for (unsigned i = 0; i < length; ++i) { 69 for (unsigned i = 0; i < length; ++i) {
71 const HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i )); 70 const HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i ));
72 if (!inputElement || !inputElement->checked()) 71 if (!inputElement || !inputElement->checked())
73 continue; 72 continue;
74 return inputElement->value(); 73 return inputElement->value();
75 } 74 }
76 return String(); 75 return String();
77 } 76 }
78 77
79 void RadioNodeList::setValue(const String& value) 78 void RadioNodeList::setValue(const String& value)
80 { 79 {
81 if (m_onlyMatchImgElements) 80 if (shouldOnlyMatchImgElements())
82 return; 81 return;
83 unsigned length = this->length(); 82 unsigned length = this->length();
84 for (unsigned i = 0; i < length; ++i) { 83 for (unsigned i = 0; i < length; ++i) {
85 HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i)); 84 HTMLInputElement* inputElement = toRadioButtonInputElement(*item(i));
86 if (!inputElement || inputElement->value() != value) 85 if (!inputElement || inputElement->value() != value)
87 continue; 86 continue;
88 inputElement->setChecked(true); 87 inputElement->setChecked(true);
89 return; 88 return;
90 } 89 }
91 } 90 }
92 91
93 bool RadioNodeList::matchesByIdOrName(const Element& testElement) const 92 bool RadioNodeList::matchesByIdOrName(const Element& testElement) const
94 { 93 {
95 return testElement.getIdAttribute() == m_name || testElement.getNameAttribut e() == m_name; 94 return testElement.getIdAttribute() == m_name || testElement.getNameAttribut e() == m_name;
96 } 95 }
97 96
98 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl ement) const 97 bool RadioNodeList::checkElementMatchesRadioNodeListFilter(const Element& testEl ement) const
99 { 98 {
100 ASSERT(!m_onlyMatchImgElements); 99 ASSERT(!shouldOnlyMatchImgElements());
101 ASSERT(isHTMLObjectElement(testElement) || testElement.isFormControlElement( )); 100 ASSERT(isHTMLObjectElement(testElement) || testElement.isFormControlElement( ));
102 if (isHTMLFormElement(ownerNode())) { 101 if (isHTMLFormElement(ownerNode())) {
103 HTMLFormElement* formElement = toHTMLElement(testElement).formOwner(); 102 HTMLFormElement* formElement = toHTMLElement(testElement).formOwner();
104 if (!formElement || formElement != ownerNode()) 103 if (!formElement || formElement != ownerNode())
105 return false; 104 return false;
106 } 105 }
107 106
108 return matchesByIdOrName(testElement); 107 return matchesByIdOrName(testElement);
109 } 108 }
110 109
111 bool RadioNodeList::elementMatches(const Element& element) const 110 bool RadioNodeList::elementMatches(const Element& element) const
112 { 111 {
113 if (m_onlyMatchImgElements) { 112 if (shouldOnlyMatchImgElements()) {
114 if (!isHTMLImageElement(element)) 113 if (!isHTMLImageElement(element))
115 return false; 114 return false;
116 115
117 if (toHTMLElement(element).formOwner() != ownerNode()) 116 if (toHTMLElement(element).formOwner() != ownerNode())
118 return false; 117 return false;
119 118
120 return matchesByIdOrName(element); 119 return matchesByIdOrName(element);
121 } 120 }
122 121
123 if (!isHTMLObjectElement(element) && !element.isFormControlElement()) 122 if (!isHTMLObjectElement(element) && !element.isFormControlElement())
124 return false; 123 return false;
125 124
126 if (isHTMLInputElement(element) && toHTMLInputElement(element).isImageButton ()) 125 if (isHTMLInputElement(element) && toHTMLInputElement(element).isImageButton ())
127 return false; 126 return false;
128 127
129 return checkElementMatchesRadioNodeListFilter(element); 128 return checkElementMatchesRadioNodeListFilter(element);
130 } 129 }
131 130
132 } // namespace 131 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/RadioNodeList.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698