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

Side by Side Diff: Source/web/WebSearchableFormData.cpp

Issue 200723002: Use new is*Element() helper functions more in web/ code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use same assertion as in operator->() Created 6 years, 9 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/web/WebPasswordFormUtils.cpp ('k') | Source/web/WebViewImpl.cpp » ('j') | 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 return !initialSelected || initialSelected->selected(); 129 return !initialSelected || initialSelected->selected();
130 } 130 }
131 131
132 // Returns true if the form element is in its default state, false otherwise. 132 // Returns true if the form element is in its default state, false otherwise.
133 // The default state is the state of the form element on initial load of the 133 // The default state is the state of the form element on initial load of the
134 // page, and varies depending upon the form element. For example, a checkbox is 134 // page, and varies depending upon the form element. For example, a checkbox is
135 // in its default state if the checked state matches the state of the checked at tribute. 135 // in its default state if the checked state matches the state of the checked at tribute.
136 bool IsInDefaultState(HTMLFormControlElement* formElement) 136 bool IsInDefaultState(HTMLFormControlElement* formElement)
137 { 137 {
138 if (formElement->hasTagName(HTMLNames::inputTag)) { 138 ASSERT(formElement);
139 const HTMLInputElement* inputElement = toHTMLInputElement(formElement); 139 if (isHTMLInputElement(*formElement)) {
140 if (inputElement->isCheckbox() || inputElement->isRadioButton()) 140 const HTMLInputElement& inputElement = toHTMLInputElement(*formElement);
141 return inputElement->checked() == inputElement->hasAttribute(checked Attr); 141 if (inputElement.isCheckbox() || inputElement.isRadioButton())
142 } else if (formElement->hasTagName(HTMLNames::selectTag)) { 142 return inputElement.checked() == inputElement.hasAttribute(checkedAt tr);
143 } else if (isHTMLSelectElement(*formElement)) {
143 return IsSelectInDefaultState(toHTMLSelectElement(formElement)); 144 return IsSelectInDefaultState(toHTMLSelectElement(formElement));
144 } 145 }
145 return true; 146 return true;
146 } 147 }
147 148
148 // Look for a suitable search text field in a given HTMLFormElement 149 // Look for a suitable search text field in a given HTMLFormElement
149 // Return nothing if one of those items are found: 150 // Return nothing if one of those items are found:
150 // - A text area field 151 // - A text area field
151 // - A file upload field 152 // - A file upload field
152 // - A Password field 153 // - A Password field
153 // - More than one text field 154 // - More than one text field
154 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form) 155 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form)
155 { 156 {
156 HTMLInputElement* textElement = 0; 157 HTMLInputElement* textElement = 0;
157 const Vector<FormAssociatedElement*>& element = form->associatedElements(); 158 const Vector<FormAssociatedElement*>& element = form->associatedElements();
158 for (Vector<FormAssociatedElement*>::const_iterator i(element.begin()); i != element.end(); ++i) { 159 for (Vector<FormAssociatedElement*>::const_iterator i(element.begin()); i != element.end(); ++i) {
159 if (!(*i)->isFormControlElement()) 160 if (!(*i)->isFormControlElement())
160 continue; 161 continue;
161 162
162 HTMLFormControlElement* control = toHTMLFormControlElement(*i); 163 HTMLFormControlElement* control = toHTMLFormControlElement(*i);
163 164
164 if (control->isDisabledFormControl() || control->name().isNull()) 165 if (control->isDisabledFormControl() || control->name().isNull())
165 continue; 166 continue;
166 167
167 if (!IsInDefaultState(control) || control->hasTagName(textareaTag)) 168 if (!IsInDefaultState(control) || isHTMLTextAreaElement(*control))
168 return 0; 169 return 0;
169 170
170 if (control->hasTagName(HTMLNames::inputTag) && control->willValidate()) { 171 if (isHTMLInputElement(*control) && control->willValidate()) {
171 const HTMLInputElement* input = toHTMLInputElement(control); 172 const HTMLInputElement& input = toHTMLInputElement(*control);
172 173
173 // Return nothing if a file upload field or a password field are fou nd. 174 // Return nothing if a file upload field or a password field are fou nd.
174 if (input->isFileUpload() || input->isPasswordField()) 175 if (input.isFileUpload() || input.isPasswordField())
175 return 0; 176 return 0;
176 177
177 if (input->isTextField()) { 178 if (input.isTextField()) {
178 if (textElement) { 179 if (textElement) {
179 // The auto-complete bar only knows how to fill in one value . 180 // The auto-complete bar only knows how to fill in one value .
180 // This form has multiple fields; don't treat it as searchab le. 181 // This form has multiple fields; don't treat it as searchab le.
181 return 0; 182 return 0;
182 } 183 }
183 textElement = toHTMLInputElement(control); 184 textElement = toHTMLInputElement(control);
184 } 185 }
185 } 186 }
186 } 187 }
187 return textElement; 188 return textElement;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 284
284 String action(formElement->action()); 285 String action(formElement->action());
285 KURL url(formElement->document().completeURL(action.isNull() ? "" : action)) ; 286 KURL url(formElement->document().completeURL(action.isNull() ? "" : action)) ;
286 RefPtr<FormData> formData = FormData::create(encodedString); 287 RefPtr<FormData> formData = FormData::create(encodedString);
287 url.setQuery(formData->flattenToString()); 288 url.setQuery(formData->flattenToString());
288 m_url = url; 289 m_url = url;
289 m_encoding = String(encoding.name()); 290 m_encoding = String(encoding.name());
290 } 291 }
291 292
292 } // namespace blink 293 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebPasswordFormUtils.cpp ('k') | Source/web/WebViewImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698