Chromium Code Reviews

Side by Side Diff: chrome/browser/chromeos/login/new_user_view.cc

Issue 6069006: Trim whitespaces from username (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/chromeos/login/new_user_view.h" 5 #include "chrome/browser/chromeos/login/new_user_view.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 45 matching lines...)
56 56
57 // Textfield that adds domain to the entered username if focus is lost and 57 // Textfield that adds domain to the entered username if focus is lost and
58 // username doesn't have full domain. 58 // username doesn't have full domain.
59 class UsernameField : public chromeos::TextfieldWithMargin { 59 class UsernameField : public chromeos::TextfieldWithMargin {
60 public: 60 public:
61 explicit UsernameField(chromeos::NewUserView* controller) 61 explicit UsernameField(chromeos::NewUserView* controller)
62 : controller_(controller) {} 62 : controller_(controller) {}
63 63
64 // views::Textfield overrides: 64 // views::Textfield overrides:
65 virtual void WillLoseFocus() { 65 virtual void WillLoseFocus() {
66 if (!text().empty()) { 66 string16 user_input;
67 std::string username = UTF16ToUTF8(text()); 67 bool was_trim = TrimWhitespace(text(), TRIM_ALL, &user_input) != TRIM_NONE;
68 if (!user_input.empty()) {
69 std::string username = UTF16ToUTF8(user_input);
68 70
69 if (username.find('@') == std::string::npos) { 71 if (username.find('@') == std::string::npos) {
70 username += kDefaultDomain; 72 username += kDefaultDomain;
71 SetText(UTF8ToUTF16(username)); 73 SetText(UTF8ToUTF16(username));
74 was_trim = false;
72 } 75 }
73 } 76 }
77
78 if (was_trim)
79 SetText(user_input);
74 } 80 }
75 81
76 // Overridden from views::View: 82 // Overridden from views::View:
77 virtual bool OnKeyPressed(const views::KeyEvent& e) { 83 virtual bool OnKeyPressed(const views::KeyEvent& e) {
78 if (e.GetKeyCode() == app::VKEY_LEFT) { 84 if (e.GetKeyCode() == app::VKEY_LEFT) {
79 return controller_->NavigateAway(); 85 return controller_->NavigateAway();
80 } 86 }
81 return false; 87 return false;
82 } 88 }
83 89
(...skipping 477 matching lines...)
561 567
562 void NewUserView::InitLink(views::Link** link) { 568 void NewUserView::InitLink(views::Link** link) {
563 *link = new views::Link(std::wstring()); 569 *link = new views::Link(std::wstring());
564 (*link)->SetController(this); 570 (*link)->SetController(this);
565 (*link)->SetNormalColor(login::kLinkColor); 571 (*link)->SetNormalColor(login::kLinkColor);
566 (*link)->SetHighlightedColor(login::kLinkColor); 572 (*link)->SetHighlightedColor(login::kLinkColor);
567 AddChildView(*link); 573 AddChildView(*link);
568 } 574 }
569 575
570 } // namespace chromeos 576 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine