Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/ui/views/avatar_menu_bubble_view.cc

Issue 10453101: Convert most of the rest of chrome to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/avatar_menu_bubble_view.h" 5 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 virtual void OnFocus() OVERRIDE; 156 virtual void OnFocus() OVERRIDE;
157 virtual void OnBlur() OVERRIDE; 157 virtual void OnBlur() OVERRIDE;
158 158
159 virtual void OnHighlightStateChanged() OVERRIDE; 159 virtual void OnHighlightStateChanged() OVERRIDE;
160 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE; 160 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE;
161 161
162 EditProfileLink* edit_link() { return edit_link_; } 162 EditProfileLink* edit_link() { return edit_link_; }
163 const AvatarMenuModel::Item& item() { return item_; } 163 const AvatarMenuModel::Item& item() { return item_; }
164 164
165 private: 165 private:
166 static SkBitmap GetBadgedIcon(const SkBitmap& icon); 166 static gfx::ImageSkia GetBadgedIcon(const gfx::ImageSkia& icon);
167 167
168 bool IsHighlighted(); 168 bool IsHighlighted();
169 169
170 EditProfileLink* edit_link_; 170 EditProfileLink* edit_link_;
171 views::ImageView* image_view_; 171 views::ImageView* image_view_;
172 AvatarMenuModel::Item item_; 172 AvatarMenuModel::Item item_;
173 views::Label* name_label_; 173 views::Label* name_label_;
174 views::Label* sync_state_label_; 174 views::Label* sync_state_label_;
175 }; 175 };
176 176
177 ProfileItemView::ProfileItemView(const AvatarMenuModel::Item& item, 177 ProfileItemView::ProfileItemView(const AvatarMenuModel::Item& item,
178 views::ButtonListener* switch_profile_listener, 178 views::ButtonListener* switch_profile_listener,
179 views::LinkListener* edit_profile_listener) 179 views::LinkListener* edit_profile_listener)
180 : views::CustomButton(switch_profile_listener), 180 : views::CustomButton(switch_profile_listener),
181 item_(item) { 181 item_(item) {
182 image_view_ = new ProfileImageView(); 182 image_view_ = new ProfileImageView();
183 SkBitmap profile_icon = *item_.icon.ToSkBitmap(); 183 gfx::ImageSkia profile_icon = *item_.icon.ToImageSkia();
184 if (item_.active) { 184 if (item_.active) {
185 SkBitmap badged_icon(GetBadgedIcon(profile_icon)); 185 gfx::ImageSkia badged_icon(GetBadgedIcon(profile_icon));
186 image_view_->SetImage(badged_icon); 186 image_view_->SetImage(badged_icon);
187 } else { 187 } else {
188 image_view_->SetImage(profile_icon); 188 image_view_->SetImage(profile_icon);
189 } 189 }
190 AddChildView(image_view_); 190 AddChildView(image_view_);
191 191
192 // Add a label to show the profile name. 192 // Add a label to show the profile name.
193 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 193 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
194 const gfx::Font base_font = rb.GetFont(ui::ResourceBundle::BaseFont); 194 const gfx::Font base_font = rb.GetFont(ui::ResourceBundle::BaseFont);
195 const int style = item_.active ? gfx::Font::BOLD : 0; 195 const int style = item_.active ? gfx::Font::BOLD : 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 void ProfileItemView::Layout() { 235 void ProfileItemView::Layout() {
236 // Profile icon. 236 // Profile icon.
237 gfx::Rect icon_rect; 237 gfx::Rect icon_rect;
238 if (item_.active) { 238 if (item_.active) {
239 // If this is the active item then the icon is already scaled and so 239 // If this is the active item then the icon is already scaled and so
240 // just use the preferred size. 240 // just use the preferred size.
241 icon_rect.set_size(image_view_->GetPreferredSize()); 241 icon_rect.set_size(image_view_->GetPreferredSize());
242 icon_rect.set_y((height() - icon_rect.height()) / 2); 242 icon_rect.set_y((height() - icon_rect.height()) / 2);
243 } else { 243 } else {
244 const SkBitmap& icon = image_view_->GetImage(); 244 const gfx::ImageSkia& icon = image_view_->GetImage();
245 icon_rect = GetCenteredAndScaledRect(icon.width(), icon.height(), 0, 0, 245 icon_rect = GetCenteredAndScaledRect(icon.width(), icon.height(), 0, 0,
246 profiles::kAvatarIconWidth, height()); 246 profiles::kAvatarIconWidth, height());
247 } 247 }
248 image_view_->SetBoundsRect(icon_rect); 248 image_view_->SetBoundsRect(icon_rect);
249 249
250 int label_x = profiles::kAvatarIconWidth + kIconMarginX; 250 int label_x = profiles::kAvatarIconWidth + kIconMarginX;
251 int max_label_width = std::max(width() - label_x, 0); 251 int max_label_width = std::max(width() - label_x, 0);
252 gfx::Size name_size = name_label_->GetPreferredSize(); 252 gfx::Size name_size = name_label_->GetPreferredSize();
253 name_size.set_width(std::min(name_size.width(), max_label_width)); 253 name_size.set_width(std::min(name_size.width(), max_label_width));
254 gfx::Size state_size = sync_state_label_->GetPreferredSize(); 254 gfx::Size state_size = sync_state_label_->GetPreferredSize();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 SchedulePaint(); 305 SchedulePaint();
306 } 306 }
307 307
308 void ProfileItemView::OnFocusStateChanged(bool has_focus) { 308 void ProfileItemView::OnFocusStateChanged(bool has_focus) {
309 if (!has_focus && state() != views::CustomButton::BS_DISABLED) 309 if (!has_focus && state() != views::CustomButton::BS_DISABLED)
310 SetState(views::CustomButton::BS_NORMAL); 310 SetState(views::CustomButton::BS_NORMAL);
311 OnHighlightStateChanged(); 311 OnHighlightStateChanged();
312 } 312 }
313 313
314 // static 314 // static
315 SkBitmap ProfileItemView::GetBadgedIcon(const SkBitmap& icon) { 315 gfx::ImageSkia ProfileItemView::GetBadgedIcon(const gfx::ImageSkia& icon) {
316 gfx::Rect icon_rect = GetCenteredAndScaledRect(icon.width(), icon.height(), 316 gfx::Rect icon_rect = GetCenteredAndScaledRect(icon.width(), icon.height(),
317 0, 0, profiles::kAvatarIconWidth, kItemHeight); 317 0, 0, profiles::kAvatarIconWidth, kItemHeight);
318 318
319 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 319 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
320 const SkBitmap* badge = rb.GetImageNamed(IDR_PROFILE_SELECTED).ToSkBitmap(); 320 const gfx::ImageSkia* badge = rb.GetImageNamed(
321 IDR_PROFILE_SELECTED).ToImageSkia();
321 const float kBadgeOverlapRatioX = 1.0f / 5.0f; 322 const float kBadgeOverlapRatioX = 1.0f / 5.0f;
322 int width = icon_rect.width() + badge->width() * kBadgeOverlapRatioX; 323 int width = icon_rect.width() + badge->width() * kBadgeOverlapRatioX;
323 const float kBadgeOverlapRatioY = 1.0f / 3.0f; 324 const float kBadgeOverlapRatioY = 1.0f / 3.0f;
324 int height = icon_rect.height() + badge->height() * kBadgeOverlapRatioY; 325 int height = icon_rect.height() + badge->height() * kBadgeOverlapRatioY;
325 326
326 gfx::Canvas canvas(gfx::Size(width, height), false); 327 gfx::Canvas canvas(gfx::Size(width, height), false);
327 canvas.DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), 0, 0, 328 canvas.DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), 0, 0,
328 icon_rect.width(), icon_rect.height(), true); 329 icon_rect.width(), icon_rect.height(), true);
329 canvas.DrawBitmapInt(*badge, width - badge->width(), 330 canvas.DrawBitmapInt(*badge, width - badge->width(),
330 height - badge->height()); 331 height - badge->height());
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 506 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
506 add_profile_link_->SetBackgroundColor(color()); 507 add_profile_link_->SetBackgroundColor(color());
507 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); 508 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6));
508 AddChildView(add_profile_link_); 509 AddChildView(add_profile_link_);
509 510
510 // If the bubble has already been shown then resize and reposition the bubble. 511 // If the bubble has already been shown then resize and reposition the bubble.
511 Layout(); 512 Layout();
512 if (GetBubbleFrameView()) 513 if (GetBubbleFrameView())
513 SizeToContents(); 514 SizeToContents();
514 } 515 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc ('k') | chrome/browser/ui/views/avatar_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698