OLD | NEW |
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/user_controller.h" | 5 #include "chrome/browser/chromeos/login/user_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 controller_->SelectUser(controller_->user_index()); | 57 controller_->SelectUser(controller_->user_index()); |
58 | 58 |
59 return views::WidgetGtk::OnButtonPress(widget, event); | 59 return views::WidgetGtk::OnButtonPress(widget, event); |
60 } | 60 } |
61 | 61 |
62 UserController* controller_; | 62 UserController* controller_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(ClickNotifyingWidget); | 64 DISALLOW_COPY_AND_ASSIGN(ClickNotifyingWidget); |
65 }; | 65 }; |
66 | 66 |
| 67 // Returns tooltip text for user name. Tooltip contains user's display name |
| 68 // and his email domain to distinguish this user from the other one with the |
| 69 // same display name. |
| 70 std::string GetNameTooltip(const UserManager::User& user) { |
| 71 const std::string& email = user.email(); |
| 72 size_t at_pos = email.rfind('@'); |
| 73 if (at_pos == std::string::npos) { |
| 74 NOTREACHED(); |
| 75 return std::string(); |
| 76 } |
| 77 size_t domain_start = at_pos + 1; |
| 78 std::string domain = email.substr(domain_start, |
| 79 email.length() - domain_start); |
| 80 return StringPrintf("%s (%s)", |
| 81 user.GetDisplayName().c_str(), |
| 82 domain.c_str()); |
| 83 } |
| 84 |
67 // NativeButton that will always return focus to password field. | 85 // NativeButton that will always return focus to password field. |
68 class UserEntryNativeButton : public views::NativeButton { | 86 class UserEntryNativeButton : public views::NativeButton { |
69 public: | 87 public: |
70 UserEntryNativeButton(UserController* controller, | 88 UserEntryNativeButton(UserController* controller, |
71 views::ButtonListener* listener, | 89 views::ButtonListener* listener, |
72 const std::wstring& label) | 90 const std::wstring& label) |
73 : NativeButton(listener, label), | 91 : NativeButton(listener, label), |
74 controller_(controller) {} | 92 controller_(controller) {} |
75 | 93 |
76 // Overridden from View: | 94 // Overridden from View: |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 FocusPasswordField(); | 236 FocusPasswordField(); |
219 } | 237 } |
220 } | 238 } |
221 | 239 |
222 void UserController::EnableNameTooltip(bool enable) { | 240 void UserController::EnableNameTooltip(bool enable) { |
223 if (is_guest_) | 241 if (is_guest_) |
224 return; | 242 return; |
225 | 243 |
226 std::wstring tooltip_text; | 244 std::wstring tooltip_text; |
227 if (enable) | 245 if (enable) |
228 tooltip_text = UTF8ToWide(user_.email()); | 246 tooltip_text = UTF8ToWide(GetNameTooltip(user_)); |
229 | 247 |
230 if (user_view_) | 248 if (user_view_) |
231 user_view_->SetTooltipText(tooltip_text); | 249 user_view_->SetTooltipText(tooltip_text); |
232 if (label_view_) | 250 if (label_view_) |
233 label_view_->SetTooltipText(tooltip_text); | 251 label_view_->SetTooltipText(tooltip_text); |
234 if (unselected_label_view_) | 252 if (unselected_label_view_) |
235 unselected_label_view_->SetTooltipText(tooltip_text); | 253 unselected_label_view_->SetTooltipText(tooltip_text); |
236 } | 254 } |
237 | 255 |
238 void UserController::ButtonPressed(views::Button* sender, | 256 void UserController::ButtonPressed(views::Button* sender, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 484 |
467 void UserController::SelectUser(int index) { | 485 void UserController::SelectUser(int index) { |
468 delegate_->SelectUser(index); | 486 delegate_->SelectUser(index); |
469 } | 487 } |
470 | 488 |
471 void UserController::FocusPasswordField() { | 489 void UserController::FocusPasswordField() { |
472 password_field_->RequestFocus(); | 490 password_field_->RequestFocus(); |
473 } | 491 } |
474 | 492 |
475 } // namespace chromeos | 493 } // namespace chromeos |
OLD | NEW |