| OLD | NEW |
| 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_button.h" | 5 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/command_updater.h" | 9 #include "chrome/browser/command_updater.h" |
| 10 #include "chrome/browser/managed_mode.h" | 10 #include "chrome/browser/managed_mode.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 SkBitmap squarer_bitmap; | 62 SkBitmap squarer_bitmap; |
| 63 if ((bitmap->width() == profiles::kAvatarIconWidth) && | 63 if ((bitmap->width() == profiles::kAvatarIconWidth) && |
| 64 (bitmap->height() == profiles::kAvatarIconHeight)) { | 64 (bitmap->height() == profiles::kAvatarIconHeight)) { |
| 65 // Shave a couple of columns so the bitmap is more square. So when | 65 // Shave a couple of columns so the bitmap is more square. So when |
| 66 // resized to a square aspect ratio it looks pretty. | 66 // resized to a square aspect ratio it looks pretty. |
| 67 int x = 2; | 67 int x = 2; |
| 68 bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0, | 68 bitmap->extractSubset(&squarer_bitmap, SkIRect::MakeXYWH(x, 0, |
| 69 profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight)); | 69 profiles::kAvatarIconWidth - x * 2, profiles::kAvatarIconHeight)); |
| 70 source_bitmap = &squarer_bitmap; | 70 source_bitmap = &squarer_bitmap; |
| 71 } else { | 71 } else { |
| 72 // The bitmaps size has changed. Resize what we have. | 72 // The image's size has changed. Resize what we have. |
| 73 source_bitmap = bitmap; | 73 source_bitmap = bitmap; |
| 74 } | 74 } |
| 75 // Since the target size is so small, we use our best resizer. Never pass | 75 // Since the target size is so small, we use our best resizer. Never pass |
| 76 // windows a different size because it will badly hammer it to 16x16. | 76 // windows a different size because it will badly hammer it to 16x16. |
| 77 SkBitmap sk_icon = skia::ImageOperations::Resize( | 77 SkBitmap sk_icon = skia::ImageOperations::Resize( |
| 78 *source_bitmap, | 78 *source_bitmap, |
| 79 skia::ImageOperations::RESIZE_LANCZOS3, | 79 skia::ImageOperations::RESIZE_LANCZOS3, |
| 80 16, 16); | 80 16, 16); |
| 81 icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); | 81 icon = IconUtil::CreateHICONFromSkBitmap(sk_icon); |
| 82 if (!icon) | 82 if (!icon) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 AvatarMenuButton::~AvatarMenuButton() { | 101 AvatarMenuButton::~AvatarMenuButton() { |
| 102 } | 102 } |
| 103 | 103 |
| 104 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { | 104 void AvatarMenuButton::OnPaint(gfx::Canvas* canvas) { |
| 105 if (!icon_.get()) | 105 if (!icon_.get()) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 if (old_height_ != height() || button_icon_.isNull()) { | 108 if (old_height_ != height() || button_icon_.isNull()) { |
| 109 old_height_ = height(); | 109 old_height_ = height(); |
| 110 button_icon_ = *profiles::GetAvatarIconForTitleBar( | 110 button_icon_ = *profiles::GetAvatarIconForTitleBar( |
| 111 *icon_, is_gaia_picture_, width(), height()).ToSkBitmap(); | 111 *icon_, is_gaia_picture_, width(), height()).ToImageSkia(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Scale the image to fit the width of the button. | 114 // Scale the image to fit the width of the button. |
| 115 int dst_width = std::min(button_icon_.width(), width()); | 115 int dst_width = std::min(button_icon_.width(), width()); |
| 116 // Truncate rather than rounding, so that for odd widths we put the extra | 116 // Truncate rather than rounding, so that for odd widths we put the extra |
| 117 // pixel on the left. | 117 // pixel on the left. |
| 118 int dst_x = (width() - dst_width) / 2; | 118 int dst_x = (width() - dst_width) / 2; |
| 119 | 119 |
| 120 // Scale the height and maintain aspect ratio. This means that the | 120 // Scale the height and maintain aspect ratio. This means that the |
| 121 // icon may not fit in the view. That's ok, we just vertically center it. | 121 // icon may not fit in the view. That's ok, we just vertically center it. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 | 134 |
| 135 bool AvatarMenuButton::HitTest(const gfx::Point& point) const { | 135 bool AvatarMenuButton::HitTest(const gfx::Point& point) const { |
| 136 if (incognito_) | 136 if (incognito_) |
| 137 return false; | 137 return false; |
| 138 return views::MenuButton::HitTest(point); | 138 return views::MenuButton::HitTest(point); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, | 141 void AvatarMenuButton::SetAvatarIcon(const gfx::Image& icon, |
| 142 bool is_gaia_picture) { | 142 bool is_gaia_picture) { |
| 143 icon_.reset(new gfx::Image(icon)); | 143 icon_.reset(new gfx::Image(icon)); |
| 144 button_icon_ = SkBitmap(); | 144 button_icon_ = gfx::ImageSkia(); |
| 145 is_gaia_picture_ = is_gaia_picture; | 145 is_gaia_picture_ = is_gaia_picture; |
| 146 SchedulePaint(); | 146 SchedulePaint(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // views::MenuButtonListener implementation | 149 // views::MenuButtonListener implementation |
| 150 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, | 150 void AvatarMenuButton::OnMenuButtonClicked(views::View* source, |
| 151 const gfx::Point& point) { | 151 const gfx::Point& point) { |
| 152 if (incognito_) | 152 if (incognito_) |
| 153 return; | 153 return; |
| 154 | 154 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 165 views::View::ConvertPointToScreen(this, &origin); | 165 views::View::ConvertPointToScreen(this, &origin); |
| 166 gfx::Rect bounds(origin, size()); | 166 gfx::Rect bounds(origin, size()); |
| 167 | 167 |
| 168 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, | 168 AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, |
| 169 views::BubbleBorder::TOP_LEFT, bounds, browser_); | 169 views::BubbleBorder::TOP_LEFT, bounds, browser_); |
| 170 views::BubbleDelegateView::CreateBubble(bubble); | 170 views::BubbleDelegateView::CreateBubble(bubble); |
| 171 bubble->Show(); | 171 bubble->Show(); |
| 172 | 172 |
| 173 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 173 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
| 174 } | 174 } |
| OLD | NEW |