| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const NotificationDetails& details) { | 144 const NotificationDetails& details) { |
| 145 if (type != NotificationType::LOGIN_USER_IMAGE_CHANGED || | 145 if (type != NotificationType::LOGIN_USER_IMAGE_CHANGED || |
| 146 !image_view_) | 146 !image_view_) |
| 147 return; | 147 return; |
| 148 | 148 |
| 149 UserManager::User* user = Details<UserManager::User>(details).ptr(); | 149 UserManager::User* user = Details<UserManager::User>(details).ptr(); |
| 150 if (user_.email() != user->email()) | 150 if (user_.email() != user->email()) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 user_.set_image(user->image()); | 153 user_.set_image(user->image()); |
| 154 SetImage(user_.image(), user_.image().width(), user_.image().height()); | 154 SetImage(user_.image()); |
| 155 image_view_->SchedulePaint(); | |
| 156 } | 155 } |
| 157 | 156 |
| 158 void UserController::Login() { | 157 void UserController::Login() { |
| 159 // Delegate will reenable as necessary. | 158 // Delegate will reenable as necessary. |
| 160 SetPasswordEnabled(false); | 159 SetPasswordEnabled(false); |
| 161 | 160 |
| 162 delegate_->Login(this, password_field_->text()); | 161 delegate_->Login(this, password_field_->text()); |
| 163 } | 162 } |
| 164 | 163 |
| 165 WidgetGtk* UserController::CreateControlsWindow(int index, int* height) { | 164 WidgetGtk* UserController::CreateControlsWindow(int index, int* height) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 ¶ms); | 196 ¶ms); |
| 198 window->SetBounds(gfx::Rect(0, 0, kSize, pref.height())); | 197 window->SetBounds(gfx::Rect(0, 0, kSize, pref.height())); |
| 199 window->Show(); | 198 window->Show(); |
| 200 return window; | 199 return window; |
| 201 } | 200 } |
| 202 | 201 |
| 203 WidgetGtk* UserController::CreateImageWindow(int index) { | 202 WidgetGtk* UserController::CreateImageWindow(int index) { |
| 204 image_view_ = new views::ImageView(); | 203 image_view_ = new views::ImageView(); |
| 205 image_view_->set_background( | 204 image_view_->set_background( |
| 206 views::Background::CreateSolidBackground(kBackgroundColor)); | 205 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 207 if (!is_guest_) { | 206 if (!is_guest_) |
| 208 SetImage(user_.image(), user_.image().width(), user_.image().height()); | 207 SetImage(user_.image()); |
| 209 } else { | 208 else |
| 210 SetImage(*ResourceBundle::GetSharedInstance().GetBitmapNamed( | 209 SetImage(*ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 211 IDR_LOGIN_OTHER_USER), | 210 IDR_LOGIN_OTHER_USER)); |
| 212 kSize, kSize); | |
| 213 } | |
| 214 WidgetGtk* window = new WidgetGtk(WidgetGtk::TYPE_WINDOW); | 211 WidgetGtk* window = new WidgetGtk(WidgetGtk::TYPE_WINDOW); |
| 215 window->Init(NULL, gfx::Rect()); | 212 window->Init(NULL, gfx::Rect(0, 0, kSize, kSize)); |
| 216 window->SetContentsView(image_view_); | 213 window->SetContentsView(image_view_); |
| 217 std::vector<int> params; | 214 std::vector<int> params; |
| 218 params.push_back(index); | 215 params.push_back(index); |
| 219 WmIpc::instance()->SetWindowType( | 216 WmIpc::instance()->SetWindowType( |
| 220 window->GetNativeView(), | 217 window->GetNativeView(), |
| 221 WM_IPC_WINDOW_LOGIN_IMAGE, | 218 WM_IPC_WINDOW_LOGIN_IMAGE, |
| 222 ¶ms); | 219 ¶ms); |
| 223 window->SetBounds(gfx::Rect(0, 0, kSize, kSize)); | |
| 224 window->Show(); | 220 window->Show(); |
| 225 return window; | 221 return window; |
| 226 } | 222 } |
| 227 | 223 |
| 228 WidgetGtk* UserController::CreateBorderWindow(int index, | 224 WidgetGtk* UserController::CreateBorderWindow(int index, |
| 229 int total_user_count, | 225 int total_user_count, |
| 230 int controls_height) { | 226 int controls_height) { |
| 231 WidgetGtk* window = new WidgetGtk(WidgetGtk::TYPE_WINDOW); | 227 WidgetGtk* window = new WidgetGtk(WidgetGtk::TYPE_WINDOW); |
| 232 window->Init(NULL, gfx::Rect()); | 228 window->Init(NULL, gfx::Rect()); |
| 233 window->GetRootView()->set_background( | 229 window->GetRootView()->set_background( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 window->SetContentsView(label); | 264 window->SetContentsView(label); |
| 269 int height = label->GetPreferredSize().height(); | 265 int height = label->GetPreferredSize().height(); |
| 270 std::vector<int> params; | 266 std::vector<int> params; |
| 271 params.push_back(index); | 267 params.push_back(index); |
| 272 WmIpc::instance()->SetWindowType(window->GetNativeView(), type, ¶ms); | 268 WmIpc::instance()->SetWindowType(window->GetNativeView(), type, ¶ms); |
| 273 window->SetBounds(gfx::Rect(0, 0, width, height)); | 269 window->SetBounds(gfx::Rect(0, 0, width, height)); |
| 274 window->Show(); | 270 window->Show(); |
| 275 return window; | 271 return window; |
| 276 } | 272 } |
| 277 | 273 |
| 278 void UserController::SetImage(const SkBitmap& image, | 274 void UserController::SetImage(const SkBitmap& image) { |
| 279 int desired_width, | 275 int desired_size = std::min(image.width(), image.height()); |
| 280 int desired_height) { | 276 // Desired size is not preserved if it's greater than 75% of kSize. |
| 277 if (desired_size * 4 > 3 * kSize) |
| 278 desired_size = kSize; |
| 279 image_view_->SetImageSize(gfx::Size(desired_size, desired_size)); |
| 281 image_view_->SetImage(image); | 280 image_view_->SetImage(image); |
| 282 image_view_->SetImageSize( | |
| 283 gfx::Size(std::min(desired_width, kSize), | |
| 284 std::min(desired_height, kSize))); | |
| 285 } | 281 } |
| 286 | 282 |
| 287 gfx::Rect UserController::GetScreenBounds() const { | 283 gfx::Rect UserController::GetScreenBounds() const { |
| 288 gfx::Rect screen_bounds(password_field_->bounds()); | 284 gfx::Rect screen_bounds(password_field_->bounds()); |
| 289 gfx::Point origin(screen_bounds.origin()); | 285 gfx::Point origin(screen_bounds.origin()); |
| 290 views::View::ConvertPointToScreen(password_field_->GetParent(), &origin); | 286 views::View::ConvertPointToScreen(password_field_->GetParent(), &origin); |
| 291 screen_bounds.set_origin(origin); | 287 screen_bounds.set_origin(origin); |
| 292 return screen_bounds; | 288 return screen_bounds; |
| 293 } | 289 } |
| 294 | 290 |
| 295 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |