Commit 679facce authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Added support for Hidpi in download UI

BUG=136949
TEST=Manual, see instructions below

Run chrome with --force-device-scale-factor=2 --highlight-missing-2x-resources
Ensure that the file type icon in the download bar shows up red

Review URL: https://chromiumcodereview.appspot.com/10703173

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148334 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b7cb21f
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "content/public/browser/browser_thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#if defined(TOOLKIT_GTK)
#include "base/nix/mime_util_xdg.h"
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -27,7 +27,7 @@ typedef std::string IconGroupID;
////////////////////////////////////////////////////////////////////////////////
//
// A facility to read a file containing an icon asynchronously in the IO
// thread. Returns the icon in the form of an SkBitmap.
// thread. Returns the icon in the form of an ImageSkia.
//
////////////////////////////////////////////////////////////////////////////////
class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
......@@ -43,7 +43,7 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> {
public:
// Invoked when an icon has been read. |source| is the IconLoader. If the
// icon has been successfully loaded, result is non-null. This method must
// return true if it is taking ownership of the returned bitmap.
// return true if it is taking ownership of the returned image.
virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0;
protected:
......
......@@ -14,18 +14,18 @@
#include "base/message_loop.h"
#include "chrome/browser/icon_loader.h"
#include "grit/component_extension_resources.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "webkit/glue/image_decoder.h"
namespace {
// Used with GenerateBitmapWithSize() to indicate that the image shouldn't be
// Used with GenerateImageWithSize() to indicate that the image shouldn't be
// resized.
const int kDoNotResize = -1;
......@@ -146,21 +146,21 @@ int IconMapper::Lookup(const std::string& extension,
return idr;
}
// Returns a copy of |source| that is |pixel_size| in width and height. If
// |pixel_size| is |kDoNotResize|, returns an unmodified copy of |source|.
// Returns a copy of |source| that is |dip_size| in width and height. If
// |dip_size| is |kDoNotResize|, returns an unmodified copy of |source|.
// |source| must be a square image (width == height).
SkBitmap GenerateBitmapWithSize(const SkBitmap& source, int pixel_size) {
gfx::ImageSkia ResizeImage(const gfx::ImageSkia& source, int dip_size) {
DCHECK(!source.isNull());
DCHECK(source.width() == source.height());
if (pixel_size == kDoNotResize || source.width() == pixel_size)
if (dip_size == kDoNotResize || source.width() == dip_size)
return source;
return skia::ImageOperations::Resize(
source, skia::ImageOperations::RESIZE_BEST, pixel_size, pixel_size);
return gfx::ImageSkiaOperations::CreateResizedImage(source,
gfx::Size(dip_size, dip_size));
}
int IconSizeToPixelSize(IconLoader::IconSize size) {
int IconSizeToDIPSize(IconLoader::IconSize size) {
switch (size) {
case IconLoader::SMALL: return 16;
case IconLoader::NORMAL: return 32;
......@@ -181,14 +181,9 @@ void IconLoader::ReadIcon() {
LAZY_INSTANCE_INITIALIZER;
int idr = icon_mapper.Get().Lookup(group_, icon_size_);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
scoped_refptr<base::RefCountedStaticMemory> bytes(
rb.LoadDataResourceBytes(idr, ui::SCALE_FACTOR_100P));
DCHECK(bytes.get());
SkBitmap bitmap;
if (!gfx::PNGCodec::Decode(bytes->front(), bytes->size(), &bitmap))
NOTREACHED();
const gfx::ImageSkia* image_skia = rb.GetImageNamed(idr).ToImageSkia();
image_.reset(new gfx::Image(
GenerateBitmapWithSize(bitmap, IconSizeToPixelSize(icon_size_))));
ResizeImage(*image_skia, IconSizeToDIPSize(icon_size_))));
target_message_loop_->PostTask(
FROM_HERE, base::Bind(&IconLoader::NotifyDelegate, this));
}
......@@ -10,8 +10,8 @@
#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "base/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_util_mac.h"
void IconLoader::ReadIcon() {
NSString* group = base::SysUTF8ToNSString(group_);
......@@ -33,7 +33,7 @@ void IconLoader::ReadIcon() {
default:
NOTREACHED();
}
image_.reset(new gfx::Image(gfx::NSImageToSkBitmap(icon, size, false)));
image_.reset(new gfx::Image(gfx::ImageSkiaFromResizedNSImage(icon, size)));
}
target_message_loop_->PostTask(FROM_HERE,
......
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