diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 20:42:24 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 20:42:24 +0000 |
commit | 46728b1ff43220f8515deba08a60e079d193bf4c (patch) | |
tree | 0e1d2ccc770c132576c16acb245a0c5c277e835c /chrome/browser/icon_loader_win.cc | |
parent | 6b16d779369be1df91ab891e15f9a7e5fe7bce30 (diff) | |
download | chromium_src-46728b1ff43220f8515deba08a60e079d193bf4c.zip chromium_src-46728b1ff43220f8515deba08a60e079d193bf4c.tar.gz chromium_src-46728b1ff43220f8515deba08a60e079d193bf4c.tar.bz2 |
Windows icon loader refactor in preparation for port.
Review URL: http://codereview.chromium.org/115056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/icon_loader_win.cc')
-rw-r--r-- | chrome/browser/icon_loader_win.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/chrome/browser/icon_loader_win.cc b/chrome/browser/icon_loader_win.cc new file mode 100644 index 0000000..998faf1 --- /dev/null +++ b/chrome/browser/icon_loader_win.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2009 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. + +#include "chrome/browser/icon_loader_win.h" + +#include <windows.h> +#include <shellapi.h> + +#include "app/gfx/icon_util.h" +#include "base/gfx/size.h" +#include "base/message_loop.h" +#include "base/thread.h" +#include "chrome/browser/browser_process.h" +#include "skia/include/SkBitmap.h" + +IconLoader* IconLoader::Create(const FilePath& path, IconSize size, + Delegate* delegate) { + return new IconLoaderWin(path, size, delegate); +} + +IconLoaderWin::IconLoaderWin(const FilePath& path, IconSize size, + Delegate* delegate) + : path_(path), + icon_size_(size), + bitmap_(NULL), + delegate_(delegate) { +} + +IconLoaderWin::~IconLoaderWin() { + delete bitmap_; +} + +void IconLoaderWin::Start() { + target_message_loop_ = MessageLoop::current(); + + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(this, &IconLoaderWin::ReadIcon)); +} + +void IconLoaderWin::ReadIcon() { + int size = 0; + switch (icon_size_) { + case IconLoader::SMALL: + size = SHGFI_SMALLICON; + break; + case IconLoader::NORMAL: + size = 0; + break; + case IconLoader::LARGE: + size = SHGFI_LARGEICON; + break; + default: + NOTREACHED(); + } + SHFILEINFO file_info = { 0 }; + if (!SHGetFileInfo(path_.value().c_str(), FILE_ATTRIBUTE_NORMAL, &file_info, + sizeof(SHFILEINFO), + SHGFI_ICON | size | SHGFI_USEFILEATTRIBUTES)) + return; + + ICONINFO icon_info = { 0 }; + BITMAP bitmap_info = { 0 }; + + BOOL r = ::GetIconInfo(file_info.hIcon, &icon_info); + DCHECK(r); + r = ::GetObject(icon_info.hbmMask, sizeof(bitmap_info), &bitmap_info); + DCHECK(r); + + gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); + bitmap_ = IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size); + + target_message_loop_->PostTask(FROM_HERE, + NewRunnableMethod(this, &IconLoaderWin::NotifyDelegate)); +} + +void IconLoaderWin::NotifyDelegate() { + delegate_->OnBitmapLoaded(this, bitmap_); + bitmap_ = NULL; +} |