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