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

Side by Side Diff: Source/core/html/forms/FormController.cpp

Issue 656723005: Use C++11 features in core/html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: mike's comments Created 6 years, 1 month 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
« no previous file with comments | « Source/core/html/forms/FormController.h ('k') | Source/core/html/forms/HiddenInputType.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) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (type.isEmpty() || type.find(isNotFormControlTypeCharacter) != kNotFo und || state.isFailure()) 222 if (type.isEmpty() || type.find(isNotFormControlTypeCharacter) != kNotFo und || state.isFailure())
223 return nullptr; 223 return nullptr;
224 savedFormState->appendControlState(AtomicString(name), AtomicString(type ), state); 224 savedFormState->appendControlState(AtomicString(name), AtomicString(type ), state);
225 } 225 }
226 return savedFormState.release(); 226 return savedFormState.release();
227 } 227 }
228 228
229 void SavedFormState::serializeTo(Vector<String>& stateVector) const 229 void SavedFormState::serializeTo(Vector<String>& stateVector) const
230 { 230 {
231 stateVector.append(String::number(m_controlStateCount)); 231 stateVector.append(String::number(m_controlStateCount));
232 for (FormElementStateMap::const_iterator it = m_stateForNewFormElements.begi n(); it != m_stateForNewFormElements.end(); ++it) { 232 for (const auto& formControl : m_stateForNewFormElements) {
233 const FormElementKey& key = it->key; 233 const FormElementKey& key = formControl.key;
234 const Deque<FormControlState>& queue = it->value; 234 const Deque<FormControlState>& queue = formControl.value;
235 for (Deque<FormControlState>::const_iterator queIterator = queue.begin() ; queIterator != queue.end(); ++queIterator) { 235 for (const FormControlState& formControlState : queue) {
236 stateVector.append(key.name()); 236 stateVector.append(key.name());
237 stateVector.append(key.type()); 237 stateVector.append(key.type());
238 queIterator->serializeTo(stateVector); 238 formControlState.serializeTo(stateVector);
239 } 239 }
240 } 240 }
241 } 241 }
242 242
243 void SavedFormState::appendControlState(const AtomicString& name, const AtomicSt ring& type, const FormControlState& state) 243 void SavedFormState::appendControlState(const AtomicString& name, const AtomicSt ring& type, const FormControlState& state)
244 { 244 {
245 FormElementKey key(name.impl(), type.impl()); 245 FormElementKey key(name.impl(), type.impl());
246 FormElementStateMap::iterator it = m_stateForNewFormElements.find(key); 246 FormElementStateMap::iterator it = m_stateForNewFormElements.find(key);
247 if (it != m_stateForNewFormElements.end()) { 247 if (it != m_stateForNewFormElements.end()) {
248 it->value.append(state); 248 it->value.append(state);
(...skipping 16 matching lines...) Expand all
265 FormControlState state = it->value.takeFirst(); 265 FormControlState state = it->value.takeFirst();
266 m_controlStateCount--; 266 m_controlStateCount--;
267 if (!it->value.size()) 267 if (!it->value.size())
268 m_stateForNewFormElements.remove(it); 268 m_stateForNewFormElements.remove(it);
269 return state; 269 return state;
270 } 270 }
271 271
272 Vector<String> SavedFormState::getReferencedFilePaths() const 272 Vector<String> SavedFormState::getReferencedFilePaths() const
273 { 273 {
274 Vector<String> toReturn; 274 Vector<String> toReturn;
275 for (FormElementStateMap::const_iterator it = m_stateForNewFormElements.begi n(); it != m_stateForNewFormElements.end(); ++it) { 275 for (const auto& formControl : m_stateForNewFormElements) {
276 const FormElementKey& key = it->key; 276 const FormElementKey& key = formControl.key;
277 if (!equal(key.type(), "file", 4)) 277 if (!equal(key.type(), "file", 4))
278 continue; 278 continue;
279 const Deque<FormControlState>& queue = it->value; 279 const Deque<FormControlState>& queue = formControl.value;
280 for (Deque<FormControlState>::const_iterator queIterator = queue.begin() ; queIterator != queue.end(); ++queIterator) { 280 for (const FormControlState& formControlState : queue) {
281 const Vector<FileChooserFileInfo>& selectedFiles = HTMLInputElement: :filesFromFileInputFormControlState(*queIterator); 281 const Vector<FileChooserFileInfo>& selectedFiles = HTMLInputElement: :filesFromFileInputFormControlState(formControlState);
282 for (size_t i = 0; i < selectedFiles.size(); ++i) 282 for (size_t i = 0; i < selectedFiles.size(); ++i)
283 toReturn.append(selectedFiles[i].path); 283 toReturn.append(selectedFiles[i].path);
284 } 284 }
285 } 285 }
286 return toReturn; 286 return toReturn;
287 } 287 }
288 288
289 // ---------------------------------------------------------------------------- 289 // ----------------------------------------------------------------------------
290 290
291 class FormKeyGenerator final : public NoBaseWillBeGarbageCollectedFinalized<Form KeyGenerator> { 291 class FormKeyGenerator final : public NoBaseWillBeGarbageCollectedFinalized<Form KeyGenerator> {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // attribute value of a form control. The following string literal should 414 // attribute value of a form control. The following string literal should
415 // contain some characters which are rarely used for name attribute values. 415 // contain some characters which are rarely used for name attribute values.
416 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% Blink serialized form state version 9 \n\r=&")); 416 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% Blink serialized form state version 9 \n\r=&"));
417 return signature; 417 return signature;
418 } 418 }
419 419
420 Vector<String> DocumentState::toStateVector() 420 Vector<String> DocumentState::toStateVector()
421 { 421 {
422 OwnPtrWillBeRawPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create (); 422 OwnPtrWillBeRawPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create ();
423 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap); 423 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap);
424 for (FormElementListHashSet::const_iterator it = m_formControls.begin(); it != m_formControls.end(); ++it) { 424 for (const auto& formControl : m_formControls) {
425 HTMLFormControlElementWithState* control = it->get(); 425 HTMLFormControlElementWithState* control = formControl.get();
426 ASSERT(control->inDocument()); 426 ASSERT(control->inDocument());
427 if (!control->shouldSaveAndRestoreFormControlState()) 427 if (!control->shouldSaveAndRestoreFormControlState())
428 continue; 428 continue;
429 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(*control), nullptr); 429 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(*control), nullptr);
430 if (result.isNewEntry) 430 if (result.isNewEntry)
431 result.storedValue->value = SavedFormState::create(); 431 result.storedValue->value = SavedFormState::create();
432 result.storedValue->value->appendControlState(control->name(), control-> type(), control->saveFormControlState()); 432 result.storedValue->value->appendControlState(control->name(), control-> type(), control->saveFormControlState());
433 } 433 }
434 434
435 Vector<String> stateVector; 435 Vector<String> stateVector;
436 stateVector.reserveInitialCapacity(m_formControls.size() * 4); 436 stateVector.reserveInitialCapacity(m_formControls.size() * 4);
437 stateVector.append(formStateSignature()); 437 stateVector.append(formStateSignature());
438 for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMa p->end(); ++it) { 438 for (const auto& savedFormState : *stateMap) {
439 stateVector.append(it->key); 439 stateVector.append(savedFormState.key);
440 it->value->serializeTo(stateVector); 440 savedFormState.value->serializeTo(stateVector);
441 } 441 }
442 bool hasOnlySignature = stateVector.size() == 1; 442 bool hasOnlySignature = stateVector.size() == 1;
443 if (hasOnlySignature) 443 if (hasOnlySignature)
444 stateVector.clear(); 444 stateVector.clear();
445 return stateVector; 445 return stateVector;
446 } 446 }
447 447
448 // ---------------------------------------------------------------------------- 448 // ----------------------------------------------------------------------------
449 449
450 FormController::FormController() 450 FormController::FormController()
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (ownerFormForState(control)) 525 if (ownerFormForState(control))
526 return; 526 return;
527 FormControlState state = takeStateForFormElement(control); 527 FormControlState state = takeStateForFormElement(control);
528 if (state.valueSize() > 0) 528 if (state.valueSize() > 0)
529 control.restoreFormControlState(state); 529 control.restoreFormControlState(state);
530 } 530 }
531 531
532 void FormController::restoreControlStateIn(HTMLFormElement& form) 532 void FormController::restoreControlStateIn(HTMLFormElement& form)
533 { 533 {
534 const FormAssociatedElement::List& elements = form.associatedElements(); 534 const FormAssociatedElement::List& elements = form.associatedElements();
535 for (size_t i = 0; i < elements.size(); ++i) { 535 for (const auto& element : elements) {
536 if (!elements[i]->isFormControlElementWithState()) 536 if (!element->isFormControlElementWithState())
537 continue; 537 continue;
538 HTMLFormControlElementWithState* control = toHTMLFormControlElementWithS tate(elements[i]); 538 HTMLFormControlElementWithState* control = toHTMLFormControlElementWithS tate(element);
539 if (!control->shouldSaveAndRestoreFormControlState()) 539 if (!control->shouldSaveAndRestoreFormControlState())
540 continue; 540 continue;
541 if (ownerFormForState(*control) != &form) 541 if (ownerFormForState(*control) != &form)
542 continue; 542 continue;
543 FormControlState state = takeStateForFormElement(*control); 543 FormControlState state = takeStateForFormElement(*control);
544 if (state.valueSize() > 0) 544 if (state.valueSize() > 0)
545 control->restoreFormControlState(state); 545 control->restoreFormControlState(state);
546 } 546 }
547 } 547 }
548 548
549 Vector<String> FormController::getReferencedFilePaths(const Vector<String>& stat eVector) 549 Vector<String> FormController::getReferencedFilePaths(const Vector<String>& stat eVector)
550 { 550 {
551 Vector<String> toReturn; 551 Vector<String> toReturn;
552 SavedFormStateMap map; 552 SavedFormStateMap map;
553 formStatesFromStateVector(stateVector, map); 553 formStatesFromStateVector(stateVector, map);
554 for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++ it) 554 for (const auto& savedFormState : map)
555 toReturn.appendVector(it->value->getReferencedFilePaths()); 555 toReturn.appendVector(savedFormState.value->getReferencedFilePaths());
556 return toReturn; 556 return toReturn;
557 } 557 }
558 558
559 void FormController::registerStatefulFormControl(HTMLFormControlElementWithState & control) 559 void FormController::registerStatefulFormControl(HTMLFormControlElementWithState & control)
560 { 560 {
561 m_documentState->addControl(&control); 561 m_documentState->addControl(&control);
562 } 562 }
563 563
564 void FormController::unregisterStatefulFormControl(HTMLFormControlElementWithSta te& control) 564 void FormController::unregisterStatefulFormControl(HTMLFormControlElementWithSta te& control)
565 { 565 {
566 m_documentState->removeControl(&control); 566 m_documentState->removeControl(&control);
567 } 567 }
568 568
569 } // namespace blink 569 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/forms/FormController.h ('k') | Source/core/html/forms/HiddenInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698