summaryrefslogtreecommitdiffstats
path: root/ui/gfx/icon_util.cc
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-14 00:49:46 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-14 00:49:46 +0000
commita32e66566365203a0e38259b9c100e6c9c32bef3 (patch)
tree3ee8d6a9f9a7e182ce4f0a19e6750cda21cb9660 /ui/gfx/icon_util.cc
parentc38b7c8509a2fbf735ce5851f601e7225409261a (diff)
downloadchromium_src-a32e66566365203a0e38259b9c100e6c9c32bef3.zip
chromium_src-a32e66566365203a0e38259b9c100e6c9c32bef3.tar.gz
chromium_src-a32e66566365203a0e38259b9c100e6c9c32bef3.tar.bz2
Add rudimentary support for custom cursors in Chrome Aura Windows.
The custom cursor creation code from webcursor_win.cc has been moved to a helper function CreateCursorFromDIB in the IconUtil class and is used by the webcursor code for windows and for AURA. The change in DesktopRootWindowHostWin::SetCursor is to ensure that the custom cursor passed in is set correctly on the current thread. The fix in the CursorLoaderWin::SetPlatformCursor function is necessary for custom cursors to get set correctly. The current implementation was setting the cursor back to an arrow cursor as the GetCursorId function returns the arrow resource id for unsupported cursor types which includes custom cursors. BUG=151718 R=jam Review URL: https://codereview.chromium.org/11549037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/icon_util.cc')
-rw-r--r--ui/gfx/icon_util.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/ui/gfx/icon_util.cc b/ui/gfx/icon_util.cc
index 740f841..62b6b98 100644
--- a/ui/gfx/icon_util.cc
+++ b/ui/gfx/icon_util.cc
@@ -7,9 +7,12 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_handle.h"
+#include "base/win/scoped_hdc.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/gfx/gdi_util.h"
#include "ui/gfx/size.h"
namespace {
@@ -146,6 +149,56 @@ SkBitmap* IconUtil::CreateSkBitmapFromHICON(HICON icon) {
return new SkBitmap(CreateSkBitmapFromHICONHelper(icon, icon_size));
}
+HICON IconUtil::CreateCursorFromDIB(const gfx::Size& icon_size,
+ const gfx::Point& hotspot,
+ const void* dib_bits,
+ size_t dib_size) {
+ BITMAPINFO icon_bitmap_info = {0};
+ gfx::CreateBitmapHeader(
+ icon_size.width(),
+ icon_size.height(),
+ reinterpret_cast<BITMAPINFOHEADER*>(&icon_bitmap_info));
+
+ base::win::ScopedGetDC dc(NULL);
+ base::win::ScopedCreateDC working_dc(CreateCompatibleDC(dc));
+ base::win::ScopedGDIObject<HBITMAP> bitmap_handle(
+ CreateDIBSection(dc,
+ &icon_bitmap_info,
+ DIB_RGB_COLORS,
+ 0,
+ 0,
+ 0));
+ if (dib_size > 0) {
+ SetDIBits(0,
+ bitmap_handle,
+ 0,
+ icon_size.height(),
+ dib_bits,
+ &icon_bitmap_info,
+ DIB_RGB_COLORS);
+ }
+
+ HBITMAP old_bitmap = reinterpret_cast<HBITMAP>(
+ SelectObject(working_dc, bitmap_handle));
+ SetBkMode(working_dc, TRANSPARENT);
+ SelectObject(working_dc, old_bitmap);
+
+ base::win::ScopedGDIObject<HBITMAP> mask(
+ CreateBitmap(icon_size.width(),
+ icon_size.height(),
+ 1,
+ 1,
+ NULL));
+ ICONINFO ii = {0};
+ ii.fIcon = FALSE;
+ ii.xHotspot = hotspot.x();
+ ii.yHotspot = hotspot.y();
+ ii.hbmMask = mask;
+ ii.hbmColor = bitmap_handle;
+
+ return CreateIconIndirect(&ii);
+}
+
SkBitmap IconUtil::CreateSkBitmapFromHICONHelper(HICON icon,
const gfx::Size& s) {
DCHECK(icon);