OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profiles/avatar_menu.h" | 5 #include "chrome/browser/profiles/avatar_menu.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "ash/frame/frame_util.h" |
10 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "ui/gfx/image/image.h" |
12 #include "grit/theme_resources.h" | |
13 #include "ui/base/resource/resource_bundle.h" | |
14 #include "ui/gfx/image/image_skia_operations.h" | |
15 | 12 |
16 // static | 13 // static |
17 void AvatarMenu::GetImageForMenuButton(Profile* profile, | 14 void AvatarMenu::GetImageForMenuButton(Profile* profile, |
18 gfx::Image* image, | 15 gfx::Image* image, |
19 bool* is_rectangle) { | 16 bool* is_rectangle) { |
20 static const gfx::ImageSkia* holder = | |
21 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
22 IDR_AVATAR_HOLDER); | |
23 static const gfx::ImageSkia* holder_mask = | |
24 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
25 IDR_AVATAR_HOLDER_MASK); | |
26 // ChromeOS avatar icon is circular. | 17 // ChromeOS avatar icon is circular. |
27 *is_rectangle = false; | 18 *is_rectangle = false; |
28 | 19 *image = ash::GetAvatarImageForContext(profile); |
29 // Find the user for this profile. | |
30 std::string user_id_hash = | |
31 chromeos::ProfileHelper::GetUserIdHashFromProfile(profile); | |
32 chromeos::UserList users = chromeos::UserManager::Get()->GetLoggedInUsers(); | |
33 | |
34 for (chromeos::UserList::const_iterator it = users.begin(); | |
35 it != users.end(); ++it) { | |
36 if ((*it)->username_hash() == user_id_hash) { | |
37 gfx::ImageSkia avatar = (*it)->image(); | |
38 gfx::ImageSkia resized = gfx::ImageSkiaOperations::CreateResizedImage( | |
39 avatar, skia::ImageOperations::RESIZE_BEST, holder->size()); | |
40 gfx::ImageSkia masked = | |
41 gfx::ImageSkiaOperations::CreateMaskedImage(resized, *holder_mask); | |
42 gfx::ImageSkia result = | |
43 gfx::ImageSkiaOperations::CreateSuperimposedImage(*holder, masked); | |
44 *image = gfx::Image(result); | |
45 return; | |
46 } | |
47 LOG(FATAL) << "avatar image for the profile '" | |
48 << profile->GetProfileName() << "' not found"; | |
49 } | |
50 } | 20 } |
OLD | NEW |