OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/autofill/expanding_textfield.h" | 5 #include "chrome/browser/ui/views/autofill/expanding_textfield.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 45 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
46 kManualInputRowPadding)); | 46 kManualInputRowPadding)); |
47 } | 47 } |
48 | 48 |
49 ExpandingTextfield::~ExpandingTextfield() {} | 49 ExpandingTextfield::~ExpandingTextfield() {} |
50 | 50 |
51 void ExpandingTextfield::SetText(const base::string16& text) { | 51 void ExpandingTextfield::SetText(const base::string16& text) { |
52 textfields_.front()->SetText(text); | 52 textfields_.front()->SetText(text); |
53 std::vector<base::string16> strings; | 53 std::vector<base::string16> strings = base::SplitString( |
54 base::SplitStringDontTrim(text, '\n', &strings); | 54 text, base::string16(1, '\n'), |
| 55 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
55 | 56 |
56 size_t i = 0; | 57 size_t i = 0; |
57 for (std::list<DecoratedTextfield*>::iterator iter = textfields_.begin(); | 58 for (std::list<DecoratedTextfield*>::iterator iter = textfields_.begin(); |
58 iter != textfields_.end(); ++iter) { | 59 iter != textfields_.end(); ++iter) { |
59 (*iter)->SetText(i < strings.size() ? strings[i++] : base::string16()); | 60 (*iter)->SetText(i < strings.size() ? strings[i++] : base::string16()); |
60 } | 61 } |
61 | 62 |
62 for (; i < strings.size(); ++i) { | 63 for (; i < strings.size(); ++i) { |
63 textfields_.push_back(new DecoratedTextfield( | 64 textfields_.push_back(new DecoratedTextfield( |
64 strings[i], | 65 strings[i], |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void ExpandingTextfield::ForEachTextfield( | 138 void ExpandingTextfield::ForEachTextfield( |
138 void (BaseType::* f)(Param), Param p) const { | 139 void (BaseType::* f)(Param), Param p) const { |
139 for (std::list<DecoratedTextfield*>::const_iterator iter = | 140 for (std::list<DecoratedTextfield*>::const_iterator iter = |
140 textfields_.begin(); | 141 textfields_.begin(); |
141 iter != textfields_.end(); ++iter) { | 142 iter != textfields_.end(); ++iter) { |
142 base::Bind(f, base::Unretained(*iter), p).Run(); | 143 base::Bind(f, base::Unretained(*iter), p).Run(); |
143 } | 144 } |
144 } | 145 } |
145 | 146 |
146 } // namespace autofill | 147 } // namespace autofill |
OLD | NEW |