Commit 9769bd1e authored by mlerman@chromium.org's avatar mlerman@chromium.org

Bring back support for 38x31 avatars.

The avatar icons should not look skewed in any setting.

This CL is a partial revert of https://codereview.chromium.org/212603011/ (specifically, the portions that changed the dimensions of the avatar icons).

BUG=367022,369495,341608

Review URL: https://codereview.chromium.org/268073005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270008 0039d316-1c4b-4281-b951-d872f2087c98
parent 4ea414b4
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkScalar.h" #include "third_party/skia/include/core/SkScalar.h"
...@@ -22,6 +23,8 @@ ...@@ -22,6 +23,8 @@
#include "ui/gfx/image/canvas_image_source.h" #include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
// Helper methods for transforming and drawing avatar icons. // Helper methods for transforming and drawing avatar icons.
namespace { namespace {
...@@ -184,7 +187,7 @@ struct IconResourceInfo { ...@@ -184,7 +187,7 @@ struct IconResourceInfo {
}; };
const int kAvatarIconWidth = 38; const int kAvatarIconWidth = 38;
const int kAvatarIconHeight = 38; const int kAvatarIconHeight = 31;
const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4); const SkColor kAvatarTutorialBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xf4);
const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc); const SkColor kAvatarTutorialContentTextColor = SkColorSetRGB(0xc6, 0xda, 0xfc);
const SkColor kAvatarBubbleAccountsBackgroundColor = const SkColor kAvatarBubbleAccountsBackgroundColor =
...@@ -264,6 +267,25 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, ...@@ -264,6 +267,25 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
return gfx::Image(gfx::ImageSkia(source.release(), dst_size)); return gfx::Image(gfx::ImageSkia(source.release(), dst_size));
} }
SkBitmap GetAvatarIconAsSquare(const SkBitmap& source_bitmap,
int scale_factor) {
SkBitmap square_bitmap;
if ((source_bitmap.width() == scale_factor * profiles::kAvatarIconWidth) &&
(source_bitmap.height() == scale_factor * profiles::kAvatarIconHeight)) {
// Shave a couple of columns so the |source_bitmap| is more square. So when
// resized to a square aspect ratio it looks pretty.
gfx::Rect frame(scale_factor * profiles::kAvatarIconWidth,
scale_factor * profiles::kAvatarIconHeight);
frame.Inset(scale_factor * 2, 0, scale_factor * 2, 0);
source_bitmap.extractSubset(&square_bitmap, gfx::RectToSkIRect(frame));
} else {
// If not the avatar icon's aspect ratio, the image should be square.
DCHECK(source_bitmap.width() == source_bitmap.height());
square_bitmap = source_bitmap;
}
return square_bitmap;
}
// Helper methods for accessing, transforming and drawing avatar icons. // Helper methods for accessing, transforming and drawing avatar icons.
size_t GetDefaultAvatarIconCount() { size_t GetDefaultAvatarIconCount() {
return kDefaultAvatarIconsCount; return kDefaultAvatarIconsCount;
......
...@@ -17,6 +17,8 @@ namespace gfx { ...@@ -17,6 +17,8 @@ namespace gfx {
class Image; class Image;
} }
class SkBitmap;
namespace profiles { namespace profiles {
// Avatar access. // Avatar access.
...@@ -63,6 +65,7 @@ bool IsDefaultAvatarIconIndex(size_t index); ...@@ -63,6 +65,7 @@ bool IsDefaultAvatarIconIndex(size_t index);
// Checks if the given URL points to one of the default avatar icons. If it // Checks if the given URL points to one of the default avatar icons. If it
// is, returns true and its index through |icon_index|. If not, returns false. // is, returns true and its index through |icon_index|. If not, returns false.
bool IsDefaultAvatarIconUrl(const std::string& icon_url, size_t *icon_index); bool IsDefaultAvatarIconUrl(const std::string& icon_url, size_t *icon_index);
// Returns a version of |image| of a specific size. Note that no checks are // Returns a version of |image| of a specific size. Note that no checks are
// done on the width/height so make sure they're reasonable values; in the // done on the width/height so make sure they're reasonable values; in the
// range of 16-256 is probably best. // range of 16-256 is probably best.
...@@ -85,6 +88,10 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image, ...@@ -85,6 +88,10 @@ gfx::Image GetAvatarIconForTitleBar(const gfx::Image& image,
int dst_width, int dst_width,
int dst_height); int dst_height);
// Returns a bitmap with a couple of columns shaved off so it is more square,
// so that when resized to a square aspect ratio it looks pretty.
SkBitmap GetAvatarIconAsSquare(const SkBitmap& source_bitmap, int scale_factor);
} // namespace profiles } // namespace profiles
#endif // CHROME_BROWSER_PROFILES_PROFILE_AVATAR_ICON_UTIL_H_ #endif // CHROME_BROWSER_PROFILES_PROFILE_AVATAR_ICON_UTIL_H_
...@@ -43,8 +43,7 @@ ...@@ -43,8 +43,7 @@
#include "ui/gfx/icon_util.h" #include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_family.h" #include "ui/gfx/image/image_family.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/skia_util.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -111,18 +110,16 @@ const int kProfileAvatarIconResources2x[] = { ...@@ -111,18 +110,16 @@ const int kProfileAvatarIconResources2x[] = {
SkBitmap BadgeIcon(const SkBitmap& app_icon_bitmap, SkBitmap BadgeIcon(const SkBitmap& app_icon_bitmap,
const SkBitmap& avatar_bitmap, const SkBitmap& avatar_bitmap,
int scale_factor) { int scale_factor) {
// All icons, whether cartoon, GAIA or placeholder, should be square. SkBitmap source_bitmap =
// TODO(mlerman) - uncomment the ASSERT once noms@ lands the square images. profiles::GetAvatarIconAsSquare(avatar_bitmap, scale_factor);
// DCHECK(avatar_bitmap.width() == avatar_bitmap.height());
int avatar_badge_size = kProfileAvatarBadgeSize; int avatar_badge_size = kProfileAvatarBadgeSize;
if (app_icon_bitmap.width() != kShortcutIconSize) { if (app_icon_bitmap.width() != kShortcutIconSize) {
avatar_badge_size = avatar_badge_size =
app_icon_bitmap.width() * kProfileAvatarBadgeSize / kShortcutIconSize; app_icon_bitmap.width() * kProfileAvatarBadgeSize / kShortcutIconSize;
} }
SkBitmap sk_icon = skia::ImageOperations::Resize( SkBitmap sk_icon = skia::ImageOperations::Resize(
avatar_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, avatar_badge_size, source_bitmap, skia::ImageOperations::RESIZE_LANCZOS3, avatar_badge_size,
avatar_bitmap.height() * avatar_badge_size / avatar_bitmap.width()); source_bitmap.height() * avatar_badge_size / source_bitmap.width());
// Overlay the avatar on the icon, anchoring it to the bottom-right of the // Overlay the avatar on the icon, anchoring it to the bottom-right of the
// icon. // icon.
......
...@@ -106,7 +106,7 @@ html[dir=rtl] #account-picture-wrapper { ...@@ -106,7 +106,7 @@ html[dir=rtl] #account-picture-wrapper {
} }
#profiles-list > * { #profiles-list > * {
height: 47px; height: 40px;
} }
#profiles-list:focus { #profiles-list:focus {
...@@ -114,7 +114,7 @@ html[dir=rtl] #account-picture-wrapper { ...@@ -114,7 +114,7 @@ html[dir=rtl] #account-picture-wrapper {
} }
.profile-img { .profile-img {
height: 38px; height: 31px;
padding: 3px; padding: 3px;
vertical-align: middle; vertical-align: middle;
width: 38px; width: 38px;
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
} }
.profile-icon-grid-item { .profile-icon-grid-item {
height: 38px; height: 31px;
margin: 2px 4px; margin: 2px 4px;
padding: 4px; padding: 4px;
width: 38px; width: 38px;
} }
.profile-icon { .profile-icon {
height: 38px; height: 31px;
width: 38px; width: 38px;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "skia/ext/image_operations.h" #include "skia/ext/image_operations.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/icon_util.h" #include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/views/win/hwnd_util.h" #include "ui/views/win/hwnd_util.h"
...@@ -41,15 +40,17 @@ void SetOverlayIcon(HWND hwnd, scoped_ptr<SkBitmap> bitmap) { ...@@ -41,15 +40,17 @@ void SetOverlayIcon(HWND hwnd, scoped_ptr<SkBitmap> bitmap) {
base::win::ScopedGDIObject<HICON> icon; base::win::ScopedGDIObject<HICON> icon;
if (bitmap.get()) { if (bitmap.get()) {
const size_t kOverlayIconSize = 16; DCHECK_GE(bitmap.get()->width(), bitmap.get()->height());
const SkBitmap* source_bitmap = bitmap.get(); // Maintain aspect ratio on resize.
const int kOverlayIconSize = 16;
// Maintain aspect ratio on resize. Image is assumed to be square. int resized_height =
bitmap.get()->height() * kOverlayIconSize / bitmap.get()->width();
DCHECK_GE(kOverlayIconSize, resized_height);
// Since the target size is so small, we use our best resizer. // Since the target size is so small, we use our best resizer.
SkBitmap sk_icon = skia::ImageOperations::Resize( SkBitmap sk_icon = skia::ImageOperations::Resize(
*source_bitmap, *bitmap.get(),
skia::ImageOperations::RESIZE_LANCZOS3, skia::ImageOperations::RESIZE_LANCZOS3,
kOverlayIconSize, kOverlayIconSize); kOverlayIconSize, resized_height);
// Paint the resized icon onto a 16x16 canvas otherwise Windows will badly // Paint the resized icon onto a 16x16 canvas otherwise Windows will badly
// hammer it to 16x16. // hammer it to 16x16.
...@@ -57,8 +58,7 @@ void SetOverlayIcon(HWND hwnd, scoped_ptr<SkBitmap> bitmap) { ...@@ -57,8 +58,7 @@ void SetOverlayIcon(HWND hwnd, scoped_ptr<SkBitmap> bitmap) {
offscreen_bitmap.allocN32Pixels(kOverlayIconSize, kOverlayIconSize); offscreen_bitmap.allocN32Pixels(kOverlayIconSize, kOverlayIconSize);
SkCanvas offscreen_canvas(offscreen_bitmap); SkCanvas offscreen_canvas(offscreen_bitmap);
offscreen_canvas.clear(SK_ColorTRANSPARENT); offscreen_canvas.clear(SK_ColorTRANSPARENT);
offscreen_canvas.drawBitmap(sk_icon, 0, 0); offscreen_canvas.drawBitmap(sk_icon, 0, kOverlayIconSize - resized_height);
icon.Set(IconUtil::CreateHICONFromSkBitmap(offscreen_bitmap)); icon.Set(IconUtil::CreateHICONFromSkBitmap(offscreen_bitmap));
if (!icon.Get()) if (!icon.Get())
return; return;
...@@ -84,8 +84,11 @@ void DrawTaskbarDecoration(gfx::NativeWindow window, const gfx::Image* image) { ...@@ -84,8 +84,11 @@ void DrawTaskbarDecoration(gfx::NativeWindow window, const gfx::Image* image) {
// Copy the image since we're going to use it on a separate thread and // Copy the image since we're going to use it on a separate thread and
// gfx::Image isn't thread safe. // gfx::Image isn't thread safe.
scoped_ptr<SkBitmap> bitmap( scoped_ptr<SkBitmap> bitmap;
image ? new SkBitmap(*image->ToSkBitmap()) : NULL); if (image) {
bitmap.reset(new SkBitmap(
profiles::GetAvatarIconAsSquare(*image->ToSkBitmap(), 1)));
}
content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior( content::BrowserThread::GetBlockingPool()->PostWorkerTaskWithShutdownBehavior(
FROM_HERE, base::Bind(&SetOverlayIcon, hwnd, Passed(&bitmap)), FROM_HERE, base::Bind(&SetOverlayIcon, hwnd, Passed(&bitmap)),
base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment