OLD | NEW |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return form->document()->completeURL(action.isNull() ? "" : action).protocol
Is("http"); | 78 return form->document()->completeURL(action.isNull() ? "" : action).protocol
Is("http"); |
79 } | 79 } |
80 | 80 |
81 // If the form does not have an activated submit button, the first submit | 81 // If the form does not have an activated submit button, the first submit |
82 // button is returned. | 82 // button is returned. |
83 HTMLFormControlElement* GetButtonToActivate(HTMLFormElement* form) | 83 HTMLFormControlElement* GetButtonToActivate(HTMLFormElement* form) |
84 { | 84 { |
85 HTMLFormControlElement* firstSubmitButton = 0; | 85 HTMLFormControlElement* firstSubmitButton = 0; |
86 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. | 86 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. |
87 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { | 87 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { |
88 if (!(*i)->isFormControlElement()) | 88 if (!(*i)->isFormControlElement()) |
89 continue; | 89 continue; |
90 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement*>
(*i); | 90 HTMLFormControlElement* control = toHTMLFormControlElement(*i); |
91 if (formElement->isActivatedSubmit()) | 91 if (control->isActivatedSubmit()) { |
92 // There's a button that is already activated for submit, return 0. | 92 // There's a button that is already activated for submit, return 0. |
93 return 0; | 93 return 0; |
94 if (!firstSubmitButton && formElement->isSuccessfulSubmitButton()) | 94 } |
95 firstSubmitButton = formElement; | 95 if (!firstSubmitButton && control->isSuccessfulSubmitButton()) |
| 96 firstSubmitButton = control; |
96 } | 97 } |
97 return firstSubmitButton; | 98 return firstSubmitButton; |
98 } | 99 } |
99 | 100 |
100 // Returns true if the selected state of all the options matches the default | 101 // Returns true if the selected state of all the options matches the default |
101 // selected state. | 102 // selected state. |
102 bool IsSelectInDefaultState(HTMLSelectElement* select) | 103 bool IsSelectInDefaultState(HTMLSelectElement* select) |
103 { | 104 { |
104 const Vector<HTMLElement*>& listItems = select->listItems(); | 105 const Vector<HTMLElement*>& listItems = select->listItems(); |
105 if (select->multiple() || select->size() > 1) { | 106 if (select->multiple() || select->size() > 1) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // - A Password field | 154 // - A Password field |
154 // - More than one text field | 155 // - More than one text field |
155 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form) | 156 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form) |
156 { | 157 { |
157 HTMLInputElement* textElement = 0; | 158 HTMLInputElement* textElement = 0; |
158 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. | 159 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. |
159 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { | 160 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { |
160 if (!(*i)->isFormControlElement()) | 161 if (!(*i)->isFormControlElement()) |
161 continue; | 162 continue; |
162 | 163 |
163 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement
*>(*i); | 164 HTMLFormControlElement* control = toHTMLFormControlElement(*i); |
164 | 165 |
165 if (formElement->isDisabledFormControl() || formElement->name().isNull()
) | 166 if (control->isDisabledFormControl() || control->name().isNull()) |
166 continue; | 167 continue; |
167 | 168 |
168 if (!IsInDefaultState(formElement) || formElement->hasTagName(HTMLNames:
:textareaTag)) | 169 if (!IsInDefaultState(control) || control->hasTagName(HTMLNames::textare
aTag)) |
169 return 0; | 170 return 0; |
170 | 171 |
171 if (formElement->hasTagName(HTMLNames::inputTag) && formElement->willVal
idate()) { | 172 if (control->hasTagName(HTMLNames::inputTag) && control->willValidate())
{ |
172 const HTMLInputElement* input = static_cast<const HTMLInputElement*>
(formElement); | 173 const HTMLInputElement* input = toHTMLInputElement(control); |
173 | 174 |
174 // Return nothing if a file upload field or a password field are fou
nd. | 175 // Return nothing if a file upload field or a password field are fou
nd. |
175 if (input->isFileUpload() || input->isPasswordField()) | 176 if (input->isFileUpload() || input->isPasswordField()) |
176 return 0; | 177 return 0; |
177 | 178 |
178 if (input->isTextField()) { | 179 if (input->isTextField()) { |
179 if (textElement) { | 180 if (textElement) { |
180 // The auto-complete bar only knows how to fill in one value
. | 181 // The auto-complete bar only knows how to fill in one value
. |
181 // This form has multiple fields; don't treat it as searchab
le. | 182 // This form has multiple fields; don't treat it as searchab
le. |
182 return 0; | 183 return 0; |
183 } | 184 } |
184 textElement = toHTMLInputElement(formElement); | 185 textElement = toHTMLInputElement(control); |
185 } | 186 } |
186 } | 187 } |
187 } | 188 } |
188 return textElement; | 189 return textElement; |
189 } | 190 } |
190 | 191 |
191 // Build a search string based on a given HTMLFormElement and HTMLInputElement | 192 // Build a search string based on a given HTMLFormElement and HTMLInputElement |
192 // | 193 // |
193 // Search string output example from www.google.com: | 194 // Search string output example from www.google.com: |
194 // "hl=en&source=hp&biw=1085&bih=854&q={searchTerms}&btnG=Google+Search&aq=f&aqi
=&aql=&oq=" | 195 // "hl=en&source=hp&biw=1085&bih=854&q={searchTerms}&btnG=Google+Search&aq=f&aqi
=&aql=&oq=" |
195 // | 196 // |
196 // Return false if the provided HTMLInputElement is not found in the form | 197 // Return false if the provided HTMLInputElement is not found in the form |
197 bool buildSearchString(const HTMLFormElement* form, Vector<char>* encodedString,
WTF::TextEncoding* encoding, const HTMLInputElement* textElement) | 198 bool buildSearchString(const HTMLFormElement* form, Vector<char>* encodedString,
WTF::TextEncoding* encoding, const HTMLInputElement* textElement) |
198 { | 199 { |
199 bool isElementFound = false; | 200 bool isElementFound = false; |
200 | 201 |
201 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. | 202 // FIXME: Consider refactoring this code so that we don't call form->associa
tedElements() twice. |
202 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { | 203 for (Vector<FormAssociatedElement*>::const_iterator i(form->associatedElemen
ts().begin()); i != form->associatedElements().end(); ++i) { |
203 if (!(*i)->isFormControlElement()) | 204 if (!(*i)->isFormControlElement()) |
204 continue; | 205 continue; |
205 | 206 |
206 HTMLFormControlElement* formElement = static_cast<HTMLFormControlElement
*>(*i); | 207 HTMLFormControlElement* control = toHTMLFormControlElement(*i); |
207 | 208 |
208 if (formElement->isDisabledFormControl() || formElement->name().isNull()
) | 209 if (control->isDisabledFormControl() || control->name().isNull()) |
209 continue; | 210 continue; |
210 | 211 |
211 FormDataList dataList(*encoding); | 212 FormDataList dataList(*encoding); |
212 if (!formElement->appendFormData(dataList, false)) | 213 if (!control->appendFormData(dataList, false)) |
213 continue; | 214 continue; |
214 | 215 |
215 const Vector<FormDataList::Item>& items = dataList.items(); | 216 const Vector<FormDataList::Item>& items = dataList.items(); |
216 | 217 |
217 for (Vector<FormDataList::Item>::const_iterator j(items.begin()); j != i
tems.end(); ++j) { | 218 for (Vector<FormDataList::Item>::const_iterator j(items.begin()); j != i
tems.end(); ++j) { |
218 // Handle ISINDEX / <input name=isindex> specially, but only if it's | 219 // Handle ISINDEX / <input name=isindex> specially, but only if it's |
219 // the first entry. | 220 // the first entry. |
220 if (!encodedString->isEmpty() || j->data() != "isindex") { | 221 if (!encodedString->isEmpty() || j->data() != "isindex") { |
221 if (!encodedString->isEmpty()) | 222 if (!encodedString->isEmpty()) |
222 encodedString->append('&'); | 223 encodedString->append('&'); |
223 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data(
)); | 224 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data(
)); |
224 encodedString->append('='); | 225 encodedString->append('='); |
225 } | 226 } |
226 ++j; | 227 ++j; |
227 if (formElement == textElement) { | 228 if (control == textElement) { |
228 encodedString->append("{searchTerms}", 13); | 229 encodedString->append("{searchTerms}", 13); |
229 isElementFound = true; | 230 isElementFound = true; |
230 } else | 231 } else |
231 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data(
)); | 232 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data(
)); |
232 } | 233 } |
233 } | 234 } |
234 return isElementFound; | 235 return isElementFound; |
235 } | 236 } |
236 } // namespace | 237 } // namespace |
237 | 238 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 289 |
289 String action(formElement->action()); | 290 String action(formElement->action()); |
290 KURL url(formElement->document()->completeURL(action.isNull() ? "" : action)
); | 291 KURL url(formElement->document()->completeURL(action.isNull() ? "" : action)
); |
291 RefPtr<FormData> formData = FormData::create(encodedString); | 292 RefPtr<FormData> formData = FormData::create(encodedString); |
292 url.setQuery(formData->flattenToString()); | 293 url.setQuery(formData->flattenToString()); |
293 m_url = url; | 294 m_url = url; |
294 m_encoding = String(encoding.name()); | 295 m_encoding = String(encoding.name()); |
295 } | 296 } |
296 | 297 |
297 } // namespace WebKit | 298 } // namespace WebKit |
OLD | NEW |