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

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

Issue 843683005: Fix a bit of C++11 in web/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 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/WebRemoteFrameImpl.cpp ('k') | Source/web/WebSelectElement.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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // FIXME: This function is insane. This is an overly complicated way to get this information. 74 // FIXME: This function is insane. This is an overly complicated way to get this information.
75 String action(form->action()); 75 String action(form->action());
76 // The isNull() check is trying to avoid completeURL returning KURL() when p assed a null string. 76 // The isNull() check is trying to avoid completeURL returning KURL() when p assed a null string.
77 return form->document().completeURL(action.isNull() ? "" : action).protocolI s("http"); 77 return form->document().completeURL(action.isNull() ? "" : action).protocolI s("http");
78 } 78 }
79 79
80 // If the form does not have an activated submit button, the first submit 80 // If the form does not have an activated submit button, the first submit
81 // button is returned. 81 // button is returned.
82 HTMLFormControlElement* GetButtonToActivate(HTMLFormElement* form) 82 HTMLFormControlElement* GetButtonToActivate(HTMLFormElement* form)
83 { 83 {
84 HTMLFormControlElement* firstSubmitButton = 0; 84 HTMLFormControlElement* firstSubmitButton = nullptr;
85 const FormAssociatedElement::List& element = form->associatedElements(); 85 const FormAssociatedElement::List& element = form->associatedElements();
86 for (FormAssociatedElement::List::const_iterator i(element.begin()); i != el ement.end(); ++i) { 86 for (FormAssociatedElement::List::const_iterator i(element.begin()); i != el ement.end(); ++i) {
87 if (!(*i)->isFormControlElement()) 87 if (!(*i)->isFormControlElement())
88 continue; 88 continue;
89 HTMLFormControlElement* control = toHTMLFormControlElement(*i); 89 HTMLFormControlElement* control = toHTMLFormControlElement(*i);
90 if (control->isActivatedSubmit()) { 90 if (control->isActivatedSubmit()) {
91 // There's a button that is already activated for submit, return 0. 91 // There's a button that is already activated for submit, return nul lptr.
92 return 0; 92 return nullptr;
93 } 93 }
94 if (!firstSubmitButton && control->isSuccessfulSubmitButton()) 94 if (!firstSubmitButton && control->isSuccessfulSubmitButton())
95 firstSubmitButton = control; 95 firstSubmitButton = control;
96 } 96 }
97 return firstSubmitButton; 97 return firstSubmitButton;
98 } 98 }
99 99
100 // Returns true if the selected state of all the options matches the default 100 // Returns true if the selected state of all the options matches the default
101 // selected state. 101 // selected state.
102 bool IsSelectInDefaultState(HTMLSelectElement* select) 102 bool IsSelectInDefaultState(HTMLSelectElement* select)
103 { 103 {
104 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& listItems = select ->listItems(); 104 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& listItems = select- >listItems();
105 if (select->multiple() || select->size() > 1) { 105 if (select->multiple() || select->size() > 1) {
106 for (WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >::const_iterator i(listItems.begin()); i != listItems.end(); ++i) { 106 for (WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>::const_iterator i (listItems.begin()); i != listItems.end(); ++i) {
Mike West 2015/01/08 13:32:57 New loop style?
107 if (!isHTMLOptionElement(*i)) 107 if (!isHTMLOptionElement(*i))
108 continue; 108 continue;
109 HTMLOptionElement* optionElement = toHTMLOptionElement(*i); 109 HTMLOptionElement* optionElement = toHTMLOptionElement(*i);
110 if (optionElement->selected() != optionElement->hasAttribute(selecte dAttr)) 110 if (optionElement->selected() != optionElement->hasAttribute(selecte dAttr))
111 return false; 111 return false;
112 } 112 }
113 return true; 113 return true;
114 } 114 }
115 115
116 // The select is rendered as a combobox (called menulist in WebKit). At 116 // The select is rendered as a combobox (called menulist in WebKit). At
117 // least one item is selected, determine which one. 117 // least one item is selected, determine which one.
118 HTMLOptionElement* initialSelected = 0; 118 HTMLOptionElement* initialSelected = nullptr;
119 for (WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >::const_iterator i(li stItems.begin()); i != listItems.end(); ++i) { 119 for (WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>::const_iterator i(lis tItems.begin()); i != listItems.end(); ++i) {
Mike West 2015/01/08 13:32:57 Here too?
120 if (!isHTMLOptionElement(*i)) 120 if (!isHTMLOptionElement(*i))
121 continue; 121 continue;
122 HTMLOptionElement* optionElement = toHTMLOptionElement(*i); 122 HTMLOptionElement* optionElement = toHTMLOptionElement(*i);
123 if (optionElement->hasAttribute(selectedAttr)) { 123 if (optionElement->hasAttribute(selectedAttr)) {
124 // The page specified the option to select. 124 // The page specified the option to select.
125 initialSelected = optionElement; 125 initialSelected = optionElement;
126 break; 126 break;
127 } 127 }
128 if (!initialSelected) 128 if (!initialSelected)
129 initialSelected = optionElement; 129 initialSelected = optionElement;
(...skipping 19 matching lines...) Expand all
149 } 149 }
150 150
151 // Look for a suitable search text field in a given HTMLFormElement 151 // Look for a suitable search text field in a given HTMLFormElement
152 // Return nothing if one of those items are found: 152 // Return nothing if one of those items are found:
153 // - A text area field 153 // - A text area field
154 // - A file upload field 154 // - A file upload field
155 // - A Password field 155 // - A Password field
156 // - More than one text field 156 // - More than one text field
157 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form) 157 HTMLInputElement* findSuitableSearchInputElement(const HTMLFormElement* form)
158 { 158 {
159 HTMLInputElement* textElement = 0; 159 HTMLInputElement* textElement = nullptr;
160 const FormAssociatedElement::List& element = form->associatedElements(); 160 const FormAssociatedElement::List& element = form->associatedElements();
161 for (FormAssociatedElement::List::const_iterator i(element.begin()); i != el ement.end(); ++i) { 161 for (FormAssociatedElement::List::const_iterator i(element.begin()); i != el ement.end(); ++i) {
162 if (!(*i)->isFormControlElement()) 162 if (!(*i)->isFormControlElement())
163 continue; 163 continue;
164 164
165 HTMLFormControlElement* control = toHTMLFormControlElement(*i); 165 HTMLFormControlElement* control = toHTMLFormControlElement(*i);
166 166
167 if (control->isDisabledFormControl() || control->name().isNull()) 167 if (control->isDisabledFormControl() || control->name().isNull())
168 continue; 168 continue;
169 169
170 if (!IsInDefaultState(control) || isHTMLTextAreaElement(*control)) 170 if (!IsInDefaultState(control) || isHTMLTextAreaElement(*control))
171 return 0; 171 return nullptr;
172 172
173 if (isHTMLInputElement(*control) && control->willValidate()) { 173 if (isHTMLInputElement(*control) && control->willValidate()) {
174 const HTMLInputElement& input = toHTMLInputElement(*control); 174 const HTMLInputElement& input = toHTMLInputElement(*control);
175 175
176 // Return nothing if a file upload field or a password field are fou nd. 176 // Return nothing if a file upload field or a password field are fou nd.
177 if (input.type() == InputTypeNames::file || input.type() == InputTyp eNames::password) 177 if (input.type() == InputTypeNames::file || input.type() == InputTyp eNames::password)
178 return 0; 178 return nullptr;
179 179
180 if (input.isTextField()) { 180 if (input.isTextField()) {
181 if (textElement) { 181 if (textElement) {
182 // The auto-complete bar only knows how to fill in one value . 182 // The auto-complete bar only knows how to fill in one value .
183 // This form has multiple fields; don't treat it as searchab le. 183 // This form has multiple fields; don't treat it as searchab le.
184 return 0; 184 return nullptr;
185 } 185 }
186 textElement = toHTMLInputElement(control); 186 textElement = toHTMLInputElement(control);
187 } 187 }
188 } 188 }
189 } 189 }
190 return textElement; 190 return textElement;
191 } 191 }
192 192
193 // Build a search string based on a given HTMLFormElement and HTMLInputElement 193 // Build a search string based on a given HTMLFormElement and HTMLInputElement
194 // 194 //
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } else 227 } else
228 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data( )); 228 FormDataBuilder::encodeStringAsFormData(*encodedString, j->data( ));
229 } 229 }
230 } 230 }
231 return isElementFound; 231 return isElementFound;
232 } 232 }
233 } // namespace 233 } // namespace
234 234
235 WebSearchableFormData::WebSearchableFormData(const WebFormElement& form, const W ebInputElement& selectedInputElement) 235 WebSearchableFormData::WebSearchableFormData(const WebFormElement& form, const W ebInputElement& selectedInputElement)
236 { 236 {
237 RefPtrWillBeRawPtr<HTMLFormElement> formElement = static_cast<PassRefPtrWill BeRawPtr<HTMLFormElement> >(form); 237 RefPtrWillBeRawPtr<HTMLFormElement> formElement = static_cast<PassRefPtrWill BeRawPtr<HTMLFormElement>>(form);
238 HTMLInputElement* inputElement = static_cast<PassRefPtrWillBeRawPtr<HTMLInpu tElement> >(selectedInputElement).get(); 238 HTMLInputElement* inputElement = static_cast<PassRefPtrWillBeRawPtr<HTMLInpu tElement>>(selectedInputElement).get();
239 239
240 // Only consider forms that GET data. 240 // Only consider forms that GET data.
241 // Allow HTTPS only when an input element is provided. 241 // Allow HTTPS only when an input element is provided.
242 if (equalIgnoringCase(formElement->getAttribute(methodAttr), "post") 242 if (equalIgnoringCase(formElement->getAttribute(methodAttr), "post")
243 || (!IsHTTPFormSubmit(formElement.get()) && !inputElement)) 243 || (!IsHTTPFormSubmit(formElement.get()) && !inputElement))
244 return; 244 return;
245 245
246 Vector<char> encodedString; 246 Vector<char> encodedString;
247 WTF::TextEncoding encoding; 247 WTF::TextEncoding encoding;
248 248
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 String action(formElement->action()); 284 String action(formElement->action());
285 KURL url(formElement->document().completeURL(action.isNull() ? "" : action)) ; 285 KURL url(formElement->document().completeURL(action.isNull() ? "" : action)) ;
286 RefPtr<FormData> formData = FormData::create(encodedString); 286 RefPtr<FormData> formData = FormData::create(encodedString);
287 url.setQuery(formData->flattenToString()); 287 url.setQuery(formData->flattenToString());
288 m_url = url; 288 m_url = url;
289 m_encoding = String(encoding.name()); 289 m_encoding = String(encoding.name());
290 } 290 }
291 291
292 } // namespace blink 292 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebRemoteFrameImpl.cpp ('k') | Source/web/WebSelectElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698