OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profile_metrics.h" | 14 #include "chrome/browser/profiles/profile_metrics.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_init.h" | 16 #include "chrome/browser/ui/browser_init.h" |
17 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 #include "skia/ext/image_operations.h" |
| 26 #include "ui/gfx/canvas_skia.h" |
25 | 27 |
26 using content::BrowserThread; | 28 using content::BrowserThread; |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 class ProfileSwitchObserver : public ProfileManagerObserver { | 32 class ProfileSwitchObserver : public ProfileManagerObserver { |
31 public: | 33 public: |
32 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE { | 34 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 | 36 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bool AvatarMenuModel::ShouldShowAvatarMenu() { | 147 bool AvatarMenuModel::ShouldShowAvatarMenu() { |
146 return ProfileManager::IsMultipleProfilesEnabled() && | 148 return ProfileManager::IsMultipleProfilesEnabled() && |
147 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; | 149 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; |
148 } | 150 } |
149 | 151 |
150 void AvatarMenuModel::RebuildMenu() { | 152 void AvatarMenuModel::RebuildMenu() { |
151 ClearMenu(); | 153 ClearMenu(); |
152 | 154 |
153 const size_t count = profile_info_->GetNumberOfProfiles(); | 155 const size_t count = profile_info_->GetNumberOfProfiles(); |
154 for (size_t i = 0; i < count; ++i) { | 156 for (size_t i = 0; i < count; ++i) { |
155 Item* item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); | 157 Item* item = NULL; |
| 158 if (profile_info_->IsUsingCustomAvatarIconForProfileAtIndex(i)) { |
| 159 SkBitmap custom_bmp = |
| 160 profile_info_->GetGAIAPictureOfProfileAtIndex(i); |
| 161 SkBitmap rimage = skia::ImageOperations::Resize( |
| 162 custom_bmp, skia::ImageOperations::RESIZE_BEST, 29, 29); |
| 163 |
| 164 gfx::CanvasSkia canvas(38, 31, false); |
| 165 // canvas.FillRect(SkColorSetRGB(0xff, 0, 0), gfx::Rect(0, 0, 39, 32)); |
| 166 canvas.DrawBitmapInt(rimage, 4, 1); |
| 167 |
| 168 int x1 = 4; |
| 169 int y1 = 1; |
| 170 int x2 = x1 + 29; |
| 171 int y2 = y1 + 29; |
| 172 |
| 173 // Dark Shadow Top |
| 174 canvas.DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
| 175 x1 - 1, y1 - 1, x2 + 1, y1 - 1); |
| 176 canvas.DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
| 177 x1 - 1, y1, x1 - 1, y2); |
| 178 canvas.DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
| 179 x2, y1, x2, y2); |
| 180 canvas.DrawLineInt(SkColorSetARGB(89, 0, 0, 0), |
| 181 x1 - 1, y2 + 0, x2 + 1, y2 + 0); |
| 182 |
| 183 SkBitmap bmp = canvas.ExtractBitmap(); |
| 184 |
| 185 gfx::Image image2(new SkBitmap(bmp)); |
| 186 item = new Item(i, image2); |
| 187 } else { |
| 188 item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); |
| 189 } |
156 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 190 item->name = profile_info_->GetNameOfProfileAtIndex(i); |
157 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); | 191 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); |
158 if (item->sync_state.empty()) { | 192 if (item->sync_state.empty()) { |
159 item->sync_state = l10n_util::GetStringUTF16( | 193 item->sync_state = l10n_util::GetStringUTF16( |
160 IDS_PROFILES_LOCAL_PROFILE_STATE); | 194 IDS_PROFILES_LOCAL_PROFILE_STATE); |
161 } | 195 } |
162 if (browser_) { | 196 if (browser_) { |
163 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); | 197 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
164 item->active = browser_->profile()->GetPath() == path; | 198 item->active = browser_->profile()->GetPath() == path; |
165 } | 199 } |
166 items_.push_back(item); | 200 items_.push_back(item); |
167 } | 201 } |
168 } | 202 } |
169 | 203 |
170 void AvatarMenuModel::ClearMenu() { | 204 void AvatarMenuModel::ClearMenu() { |
171 STLDeleteContainerPointers(items_.begin(), items_.end()); | 205 STLDeleteContainerPointers(items_.begin(), items_.end()); |
172 items_.clear(); | 206 items_.clear(); |
173 } | 207 } |
OLD | NEW |