summaryrefslogtreecommitdiffstats
path: root/webkit/glue/webcursor.h
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 00:36:52 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 00:36:52 +0000
commit4c870b4013b3cf658c40e2c7b98e0a419ae7236f (patch)
treee701a8ab7b093e04367a0956e7ff94a702806e6c /webkit/glue/webcursor.h
parent983f7bd3fa88bbdac942dbfaf0269b1684a5c1ee (diff)
downloadchromium_src-4c870b4013b3cf658c40e2c7b98e0a419ae7236f.zip
chromium_src-4c870b4013b3cf658c40e2c7b98e0a419ae7236f.tar.gz
chromium_src-4c870b4013b3cf658c40e2c7b98e0a419ae7236f.tar.bz2
Eliminate CursorChromium's dependency on webkit/glue.
Also modified WidgetChromium to use ChromiumBridge instead of talking to ChromeClientChromium. I want to eliminate that fake interface in favor of just having our code talk directly to ChromeClientImpl, but that means a dependency on webkit/glue, so I needed to use ChromiumBridge. Long-term, I'd like to propose changes upstream to HostWindow and ChromeClient to avoid this usage of ChromiumBridge. The most impactful part of this CL is the change to move the enumeration of cursor types from WebCursor to PlatformCursor. This means that WebCursor consumers no longer have access to the type enumeration. I replaced that with helper functions on WebCursor. I think the result not only achieves the goal of breaking CursorChromium's dependency on webkit/glue but is also much cleaner. R=iyengar,eseidel Review URL: http://codereview.chromium.org/9072 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4846 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webcursor.h')
-rw-r--r--webkit/glue/webcursor.h163
1 files changed, 51 insertions, 112 deletions
diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h
index 6f555fd..92e27f3 100644
--- a/webkit/glue/webcursor.h
+++ b/webkit/glue/webcursor.h
@@ -2,132 +2,71 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef WEBCURSOR_H__
-#define WEBCURSOR_H__
+#ifndef WEBKIT_GLUE_WEBCURSOR_H_
+#define WEBKIT_GLUE_WEBCURSOR_H_
-#include "build/build_config.h"
+#include "base/gfx/point.h"
+#include "base/gfx/size.h"
-#if defined(OS_MACOSX)
-#include <CoreGraphics/CoreGraphics.h>
-#else
-#include "skia/include/SkBitmap.h"
-#endif
+#include <vector>
-// Use CGImage on the Mac and SkBitmap on other platforms. WebCursorBitmapPtr
-// is a corresponding pointer type: because CGImageRef is already a pointer
-// type, we can just use that directly in the constructor, but we need an
-// SkBitmap* in the Skia case.
-//
-// TODO(port): We should use a bitmap abstraction container.
-#if defined(OS_MACOSX)
-typedef CGImageRef WebCursorBitmap;
-typedef WebCursorBitmap WebCursorBitmapPtr;
-#else
-typedef SkBitmap WebCursorBitmap;
-typedef SkBitmap* WebCursorBitmapPtr;
+#if defined(OS_WIN)
+typedef struct HINSTANCE__* HINSTANCE;
+typedef struct HICON__* HICON;
+typedef HICON HCURSOR;
#endif
-// This class provides the functionality of a generic cursor type. The intent
-// is to stay away from platform specific code here. We do have win32 specific
-// functionality to retreive a HCURSOR from a cursor type.
-// TODO(iyengar) : Win32 specific functionality needs to be taken out of this
-// object
-class WebCursor
-{
-public:
- // Supported cursor types.
- enum Type {
- ARROW,
- IBEAM,
- WAIT,
- CROSS,
- UPARROW,
- SIZE,
- ICON,
- SIZENWSE,
- SIZENESW,
- SIZEWE,
- SIZENS,
- SIZEALL,
- NO,
- HAND,
- APPSTARTING,
- HELP,
- ALIAS,
- CELL,
- COLRESIZE,
- COPYCUR,
- ROWRESIZE,
- VERTICALTEXT,
- ZOOMIN,
- ZOOMOUT,
- CUSTOM
- };
+class Pickle;
+
+namespace WebCore {
+class Image;
+class PlatformCursor;
+}
+// This class encapsulates a cross-platform description of a cursor. Platform
+// specific methods are provided to translate the cross-platform cursor into a
+// platform specific cursor. It is also possible to serialize / de-serialize a
+// WebCursor.
+class WebCursor {
+ public:
WebCursor();
- WebCursor(Type cursor_type);
- WebCursor(const WebCursorBitmapPtr bitmap, int hotspot_x, int hotspot_y);
- ~WebCursor();
-
- WebCursor(const WebCursor& other);
- WebCursor& operator = (const WebCursor&);
-
- Type type() const { return type_; };
- int hotspot_x() const { return hotspot_x_; }
- int hotspot_y() const { return hotspot_y_; }
- const WebCursorBitmap& bitmap() const { return bitmap_; }
-
- void set_type(Type cursor_type) {
- type_ = cursor_type;
- }
-
- void set_bitmap(const WebCursorBitmap& bitmap) {
-#if defined(OS_MACOSX)
- WebCursorBitmap old_bitmap = bitmap_;
- CGImageRetain(bitmap_ = bitmap);
- CGImageRelease(old_bitmap);
-#else
- bitmap_ = bitmap;
-#endif
- }
+ explicit WebCursor(const WebCore::PlatformCursor& platform_cursor);
+
+ // Serialization / De-serialization
+ bool Deserialize(const Pickle* pickle, void** iter);
+ bool Serialize(Pickle* pickle) const;
- void set_hotspot(int hotspot_x, int hotspot_y) {
- hotspot_x_ = hotspot_x;
- hotspot_y_ = hotspot_y;
- }
+ // Returns true if GetCustomCursor should be used to allocate a platform
+ // specific cursor object. Otherwise GetCursor should be used.
+ bool IsCustom() const;
+
+ // Returns true if the current cursor object contains the same cursor as the
+ // cursor object passed in. If the current cursor is a custom cursor, we also
+ // compare the bitmaps to verify whether they are equal.
+ bool IsEqual(const WebCursor& other) const;
#if defined(OS_WIN)
- // Returns the cursor handle. If the cursor type is a win32 or safari
- // cursor, we use LoadCursor to load the cursor.
- // Returns NULL on error.
+ // If the underlying cursor type is not a custom cursor, this functions uses
+ // the LoadCursor API to load the cursor and returns it. The caller SHOULD
+ // NOT pass the resulting handling to DestroyCursor. Returns NULL on error.
HCURSOR GetCursor(HINSTANCE module_handle) const;
- // If the underlying cursor type is a custom cursor, this function converts
- // the WebCursorBitmap to a cursor and returns the same. The responsiblity of
- // freeing the cursor handle lies with the caller.
- // Returns NULL on error.
+
+ // If the underlying cursor type is a custom cursor, this function generates
+ // a cursor and returns it. The responsiblity of freeing the cursor handle
+ // lies with the caller. Returns NULL on error.
HCURSOR GetCustomCursor() const;
-#endif
-// TODO(port): Comparing CGImageRefs can be a heavyweight operation on the
-// Mac. Don't do it if it's not needed. Maybe we can avoid this type of
-// comparison on other platforms too.
-#if !defined(OS_MACOSX)
- // Returns true if the passed in WebCursorBitmap is the same as the the
- // current WebCursorBitmap. We use memcmp to compare the two bitmaps.
- bool IsSameBitmap(const WebCursorBitmap& bitmap) const;
-
- // Returns true if the current cursor object contains the same
- // cursor as the cursor object passed in. If the current cursor
- // is a custom cursor, we also compare the bitmaps to verify
- // whether they are equal.
- bool IsEqual(const WebCursor& other) const;
+ // Initialize this from the given Windows cursor.
+ void InitFromCursor(HCURSOR handle);
#endif
-protected:
- Type type_;
- int hotspot_x_;
- int hotspot_y_;
- WebCursorBitmap bitmap_;
+ private:
+ void SetCustomData(WebCore::Image* image);
+
+ int type_;
+ gfx::Point hotspot_;
+ gfx::Size custom_size_;
+ std::vector<char> custom_data_;
};
-#endif // WEBCURSOR_H__
+#endif // WEBKIT_GLUE_WEBCURSOR_H_