diff options
Diffstat (limited to 'webkit')
28 files changed, 529 insertions, 290 deletions
diff --git a/webkit/api/public/WebCursorInfo.h b/webkit/api/public/WebCursorInfo.h index c1930de..194e33b 100644 --- a/webkit/api/public/WebCursorInfo.h +++ b/webkit/api/public/WebCursorInfo.h @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: - * + * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -31,11 +31,13 @@ #ifndef WebCursorInfo_h #define WebCursorInfo_h -#error "This header file is still a work in progress; do not include!" - #include "WebImage.h" #include "WebPoint.h" +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class Cursor; } +#endif + #ifdef WIN32 typedef struct HICON__* HICON; typedef HICON HCURSOR; @@ -91,7 +93,7 @@ namespace WebKit { Type type; WebPoint hotSpot; - WebImage customData; + WebImage customImage; #ifdef WIN32 // On Windows, TypeCustom may alternatively reference an externally @@ -100,6 +102,18 @@ namespace WebKit { // responsible for managing the lifetime of this cursor handle. HCURSOR externalHandle; #endif + + explicit WebCursorInfo(Type type = TypePointer) + : type(type) + { +#ifdef WIN32 + externalHandle = 0; +#endif + } + +#if WEBKIT_IMPLEMENTATION + explicit WebCursorInfo(const WebCore::Cursor&); +#endif }; } // namespace WebKit diff --git a/webkit/api/public/WebImage.h b/webkit/api/public/WebImage.h index cef557b..7f938b5 100644 --- a/webkit/api/public/WebImage.h +++ b/webkit/api/public/WebImage.h @@ -39,6 +39,11 @@ typedef struct CGImage* CGImageRef; #endif +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class Image; } +namespace WTF { template <typename T> class PassRefPtr; } +#endif + namespace WebKit { class WebData; struct WebSize; @@ -68,6 +73,11 @@ namespace WebKit { WEBKIT_API bool isNull() const; WEBKIT_API WebSize size() const; +#if WEBKIT_IMPLEMENTATION + WebImage(const WTF::PassRefPtr<WebCore::Image>&); + WebImage& operator=(const WTF::PassRefPtr<WebCore::Image>&); +#endif + #if WEBKIT_USING_SKIA WebImage(const SkBitmap& bitmap) : m_bitmap(bitmap) { } diff --git a/webkit/api/src/WebCursorInfo.cpp b/webkit/api/src/WebCursorInfo.cpp new file mode 100644 index 0000000..73f42b0 --- /dev/null +++ b/webkit/api/src/WebCursorInfo.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WebCursorInfo.h" + +#include "Cursor.h" +#include <wtf/Assertions.h> + +using namespace WebCore; + +namespace WebKit { + +// Ensure that our publicly defined enum values never get out of sync with the +// ones declared for use within WebCore. +#define COMPILE_ASSERT_MATCHING_ENUM(name) \ + COMPILE_ASSERT(int(WebCursorInfo::name) == int(PlatformCursor::name), name) + +COMPILE_ASSERT_MATCHING_ENUM(TypePointer); +COMPILE_ASSERT_MATCHING_ENUM(TypeCross); +COMPILE_ASSERT_MATCHING_ENUM(TypeHand); +COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam); +COMPILE_ASSERT_MATCHING_ENUM(TypeWait); +COMPILE_ASSERT_MATCHING_ENUM(TypeHelp); +COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize); +COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning); +COMPILE_ASSERT_MATCHING_ENUM(TypeMove); +COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText); +COMPILE_ASSERT_MATCHING_ENUM(TypeCell); +COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu); +COMPILE_ASSERT_MATCHING_ENUM(TypeAlias); +COMPILE_ASSERT_MATCHING_ENUM(TypeProgress); +COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop); +COMPILE_ASSERT_MATCHING_ENUM(TypeCopy); +COMPILE_ASSERT_MATCHING_ENUM(TypeNone); +COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed); +COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn); +COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut); +COMPILE_ASSERT_MATCHING_ENUM(TypeCustom); + +WebCursorInfo::WebCursorInfo(const Cursor& cursor) +{ + type = static_cast<Type>(cursor.impl().type()); + hotSpot = cursor.impl().hotSpot(); + customImage = cursor.impl().customImage(); +#ifdef WIN32 + externalHandle = 0; +#endif +} + +} // namespace WebKit diff --git a/webkit/api/src/WebImageCG.cpp b/webkit/api/src/WebImageCG.cpp index 3cf1bad..34cee01 100644 --- a/webkit/api/src/WebImageCG.cpp +++ b/webkit/api/src/WebImageCG.cpp @@ -36,6 +36,7 @@ #include "WebData.h" #include "WebSize.h" +#include "Image.h" #include "ImageSource.h" #include "SharedBuffer.h" #include <wtf/PassRefPtr.h> @@ -83,6 +84,22 @@ WebSize WebImage::size() const return WebSize(CGImageGetWidth(m_imageRef), CGImageGetHeight(m_imageRef)); } +WebImage::WebImage(const PassRefPtr<Image>& image) + : m_imageRef(0) +{ + if (image.get()) + assign(image->nativeImageForCurrentFrame()); +} + +WebImage& WebImage::operator=(const PassRefPtr<Image>& image) +{ + if (image.get()) + assign(image->nativeImageForCurrentFrame()); + else + reset(); + return *this; +} + void WebImage::assign(CGImageRef imageRef) { CGImageRelease(m_imageRef); diff --git a/webkit/api/src/WebImageSkia.cpp b/webkit/api/src/WebImageSkia.cpp index 5519166..96399920 100644 --- a/webkit/api/src/WebImageSkia.cpp +++ b/webkit/api/src/WebImageSkia.cpp @@ -34,6 +34,7 @@ #include "WebData.h" #include "WebSize.h" +#include "Image.h" #include "ImageSourceSkia.h" #include "NativeImageSkia.h" #include "SharedBuffer.h" @@ -78,4 +79,19 @@ WebSize WebImage::size() const return WebSize(m_bitmap.width(), m_bitmap.height()); } +WebImage::WebImage(const PassRefPtr<Image>& image) +{ + operator=(image); +} + +WebImage& WebImage::operator=(const PassRefPtr<Image>& image) +{ + NativeImagePtr p; + if (image.get() && (p = image->nativeImageForCurrentFrame())) + assign(*p); + else + reset(); + return *this; +} + } // namespace WebKit diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc index 6341f55..d843b0f 100644 --- a/webkit/glue/chrome_client_impl.cc +++ b/webkit/glue/chrome_client_impl.cc @@ -36,6 +36,7 @@ MSVC_POP_WARNING(); #include "base/gfx/rect.h" #include "base/logging.h" #include "googleurl/src/gurl.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebInputEvent.h" #include "webkit/api/public/WebKit.h" #include "webkit/api/public/WebRect.h" @@ -48,6 +49,7 @@ MSVC_POP_WARNING(); #include "webkit/glue/webview_impl.h" #include "webkit/glue/webwidget_impl.h" +using WebKit::WebCursorInfo; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; using WebKit::WebRect; @@ -603,7 +605,7 @@ void ChromeClientImpl::popupOpenedInternal( popup_items); } -void ChromeClientImpl::SetCursor(const WebCursor& cursor) { +void ChromeClientImpl::SetCursor(const WebCursorInfo& cursor) { if (ignore_next_set_cursor_) { ignore_next_set_cursor_ = false; return; @@ -614,7 +616,7 @@ void ChromeClientImpl::SetCursor(const WebCursor& cursor) { delegate->SetCursor(webview_, cursor); } -void ChromeClientImpl::SetCursorForPlugin(const WebCursor& cursor) { +void ChromeClientImpl::SetCursorForPlugin(const WebCursorInfo& cursor) { SetCursor(cursor); // Currently, Widget::setCursor is always called after this function in // EventHandler.cpp and since we don't want that we set a flag indicating diff --git a/webkit/glue/chrome_client_impl.h b/webkit/glue/chrome_client_impl.h index ed75747..03478cd 100644 --- a/webkit/glue/chrome_client_impl.h +++ b/webkit/glue/chrome_client_impl.h @@ -11,7 +11,6 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "ChromeClientChromium.h" MSVC_POP_WARNING(); -class WebCursor; class WebViewImpl; namespace WebCore { @@ -21,6 +20,10 @@ class SecurityOrigin; struct WindowFeatures; } +namespace WebKit { +struct WebCursorInfo; +} + // Handles window-level notifications from WebCore on behalf of a WebView. class ChromeClientImpl : public WebCore::ChromeClientChromium { public: @@ -132,8 +135,8 @@ class ChromeClientImpl : public WebCore::ChromeClientChromium { const WebCore::IntRect& bounds, bool activatable); - void SetCursor(const WebCursor& cursor); - void SetCursorForPlugin(const WebCursor& cursor); + void SetCursor(const WebKit::WebCursorInfo& cursor); + void SetCursorForPlugin(const WebKit::WebCursorInfo& cursor); virtual void formStateDidChange(const WebCore::Node*); diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc index b5a4a97..e033fcb 100644 --- a/webkit/glue/chromium_bridge_impl.cc +++ b/webkit/glue/chromium_bridge_impl.cc @@ -31,11 +31,11 @@ #include "build/build_config.h" #include "googleurl/src/url_util.h" #include "skia/ext/skia_utils_win.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebScreenInfo.h" #include "webkit/glue/chrome_client_impl.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/plugins/plugin_instance.h" -#include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webplugin_impl.h" #include "webkit/glue/webview_impl.h" @@ -43,10 +43,11 @@ #if defined(OS_WIN) #include <windows.h> #include <vssym32.h> - #include "base/gfx/native_theme.h" #endif +using WebKit::WebCursorInfo; + namespace { gfx::NativeViewId ToNativeId(WebCore::Widget* widget) { @@ -176,7 +177,7 @@ IntRect ChromiumBridge::screenAvailableRect(Widget* widget) { void ChromiumBridge::widgetSetCursor(Widget* widget, const Cursor& cursor) { ChromeClientImpl* chrome_client = ToChromeClient(widget); if (chrome_client) - chrome_client->SetCursor(WebCursor(cursor.impl())); + chrome_client->SetCursor(webkit_glue::CursorToWebCursorInfo(cursor)); } void ChromiumBridge::widgetSetFocus(Widget* widget) { diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc index c695d87..f12be0b 100644 --- a/webkit/glue/glue_util.cc +++ b/webkit/glue/glue_util.cc @@ -32,6 +32,7 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "googleurl/src/gurl.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebDragData.h" #include "webkit/api/public/WebForm.h" #include "webkit/api/public/WebHistoryItem.h" @@ -230,6 +231,12 @@ WebKit::WebSize IntSizeToWebSize(const WebCore::IntSize& size) { return size; } +// Cursor conversions ---------------------------------------------------------- + +WebKit::WebCursorInfo CursorToWebCursorInfo(const WebCore::Cursor& cursor) { + return WebKit::WebCursorInfo(cursor); +} + // DragData conversions -------------------------------------------------------- WebKit::WebDragData ChromiumDataObjectToWebDragData( diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h index bb98461..beafe125 100644 --- a/webkit/glue/glue_util.h +++ b/webkit/glue/glue_util.h @@ -13,6 +13,7 @@ class GURL; namespace WebCore { class ChromiumDataObject; class CString; +class Cursor; class HistoryItem; class HTMLFormElement; class IntPoint; @@ -36,6 +37,7 @@ class WebString; class WebURL; class WebURLRequest; class WebURLResponse; +struct WebCursorInfo; struct WebPoint; struct WebRect; struct WebSize; @@ -115,6 +117,9 @@ WebKit::WebRect IntRectToWebRect(const WebCore::IntRect&); WebCore::IntSize WebSizeToIntSize(const WebKit::WebSize&); WebKit::WebSize IntSizeToWebSize(const WebCore::IntSize&); +// WebCursorInfo <- Cursor +WebKit::WebCursorInfo CursorToWebCursorInfo(const WebCore::Cursor&); + // WebDragData <-> ChromiumDataObject WebKit::WebDragData ChromiumDataObjectToWebDragData( const WTF::PassRefPtr<WebCore::ChromiumDataObject>&); diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index d197fb11..996e272 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -16,14 +16,15 @@ #include "webkit/api/public/WebInputEvent.h" #include "webkit/default_plugin/plugin_impl.h" #include "webkit/glue/glue_util.h" -#include "webkit/glue/webplugin.h" #include "webkit/glue/plugins/plugin_constants_win.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/plugins/plugin_stream_url.h" #include "webkit/glue/webkit_glue.h" +#include "webkit/glue/webplugin.h" +using WebKit::WebCursorInfo; using WebKit::WebKeyboardEvent; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; @@ -1106,9 +1107,9 @@ static bool NPEventFromWebInputEvent(const WebInputEvent& event, } bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursor* cursor) { + WebCursorInfo* cursor_info) { DCHECK(windowless_) << "events should only be received in windowless mode"; - DCHECK(cursor != NULL); + DCHECK(cursor_info != NULL); NPEvent np_event; if (!NPEventFromWebInputEvent(event, &np_event)) { @@ -1153,7 +1154,7 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, // Snag a reference to the current cursor ASAP in case the plugin modified // it. There is a nasty race condition here with the multiprocess browser // as someone might be setting the cursor in the main process as well. - *cursor = current_windowless_cursor_; + current_windowless_cursor_.GetCursorInfo(cursor_info); } if (pop_user_gesture) { diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index d3cbdbf..a6f0715 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -16,16 +16,16 @@ #include "base/ref_counted.h" #include "base/task.h" #include "third_party/npapi/bindings/npapi.h" -#include "webkit/glue/webplugin_delegate.h" #include "webkit/glue/webcursor.h" +#include "webkit/glue/webplugin_delegate.h" #if defined(OS_LINUX) typedef struct _GdkDrawable GdkPixmap; #endif namespace NPAPI { - class PluginInstance; -}; +class PluginInstance; +} // An implementation of WebPluginDelegate that proxies all calls to // the plugin process. @@ -56,7 +56,7 @@ class WebPluginDelegateImpl : public WebPluginDelegate { // only called when windowless // See NPAPI NPP_HandleEvent for more information. virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, - WebCursor* cursor); + WebKit::WebCursorInfo* cursor); virtual NPObject* GetPluginScriptableObject(); virtual void DidFinishLoadWithReason(NPReason reason); virtual int GetProcessId(); diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc index 87d8685..de4a60f 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc @@ -16,6 +16,7 @@ #include "base/process_util.h" #include "base/stats_counters.h" #include "base/string_util.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebInputEvent.h" // #include "webkit/default_plugin/plugin_impl.h" #include "webkit/glue/glue_util.h" @@ -31,6 +32,7 @@ #include "third_party/npapi/bindings/npapi_x11.h" #endif +using WebKit::WebCursorInfo; using WebKit::WebKeyboardEvent; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; @@ -794,7 +796,7 @@ static bool NPEventFromWebInputEvent(const WebInputEvent& event, } bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursor* cursor) { + WebCursorInfo* cursor_info) { DCHECK(windowless_) << "events should only be received in windowless mode"; if (first_event_time_ < 0.0) diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 771c31a..414d635 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -24,6 +24,7 @@ #include "webkit/glue/plugins/plugin_stream_url.h" #include "webkit/glue/webkit_glue.h" +using WebKit::WebCursorInfo; using WebKit::WebKeyboardEvent; using WebKit::WebInputEvent; using WebKit::WebMouseEvent; @@ -400,7 +401,7 @@ void WebPluginDelegateImpl::SetFocus() { } bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursor* cursor) { + WebCursorInfo* cursor) { DCHECK(windowless_) << "events should only be received in windowless mode"; DCHECK(cursor != NULL); // TODO: convert event into a NPEvent, and call NPP_HandleEvent(np_event). diff --git a/webkit/glue/webcursor.cc b/webkit/glue/webcursor.cc index 4fe5ce1..72ede41 100644 --- a/webkit/glue/webcursor.cc +++ b/webkit/glue/webcursor.cc @@ -4,28 +4,25 @@ #include "webkit/glue/webcursor.h" -#include "config.h" -#include "NativeImageSkia.h" -#include "PlatformCursor.h" - -#undef LOG #include "base/logging.h" #include "base/pickle.h" +#include "webkit/api/public/WebCursorInfo.h" +#include "webkit/api/public/WebImage.h" + +using WebKit::WebCursorInfo; +using WebKit::WebImage; static const int kMaxCursorDimension = 1024; WebCursor::WebCursor() - : type_(WebCore::PlatformCursor::TypePointer) { + : type_(WebCursorInfo::TypePointer) { InitPlatformData(); } -WebCursor::WebCursor(const WebCore::PlatformCursor& platform_cursor) - : type_(platform_cursor.type()), - hotspot_(platform_cursor.hotSpot().x(), platform_cursor.hotSpot().y()) { - if (IsCustom()) - SetCustomData(platform_cursor.customImage().get()); - +WebCursor::WebCursor(const WebCursorInfo& cursor_info) + : type_(WebCursorInfo::TypePointer) { InitPlatformData(); + InitFromCursorInfo(cursor_info); } WebCursor::~WebCursor() { @@ -46,6 +43,32 @@ const WebCursor& WebCursor::operator=(const WebCursor& other) { return *this; } +void WebCursor::InitFromCursorInfo(const WebCursorInfo& cursor_info) { + Clear(); + +#if defined(OS_WIN) + if (cursor_info.externalHandle) { + InitFromExternalCursor(cursor_info.externalHandle); + return; + } +#endif + + type_ = cursor_info.type; + hotspot_ = cursor_info.hotSpot; + if (IsCustom()) + SetCustomData(cursor_info.customImage); +} + +void WebCursor::GetCursorInfo(WebCursorInfo* cursor_info) const { + cursor_info->type = static_cast<WebCursorInfo::Type>(type_); + cursor_info->hotSpot = hotspot_; + ImageFromCustomData(&cursor_info->customImage); + +#if defined(OS_WIN) + cursor_info->externalHandle = external_cursor_; +#endif +} + bool WebCursor::Deserialize(const Pickle* pickle, void** iter) { int type, hotspot_x, hotspot_y, size_x, size_y, data_len; @@ -102,7 +125,7 @@ bool WebCursor::Serialize(Pickle* pickle) const { } bool WebCursor::IsCustom() const { - return type_ == WebCore::PlatformCursor::TypeCustom; + return type_ == WebCursorInfo::TypeCustom; } bool WebCursor::IsEqual(const WebCursor& other) const { @@ -118,7 +141,7 @@ bool WebCursor::IsEqual(const WebCursor& other) const { } void WebCursor::Clear() { - type_ = WebCore::PlatformCursor::TypePointer; + type_ = WebCursorInfo::TypePointer; hotspot_.set_x(0); hotspot_.set_y(0); custom_size_.set_width(0); @@ -135,23 +158,33 @@ void WebCursor::Copy(const WebCursor& other) { CopyPlatformData(other); } -#if !defined(OS_MACOSX) -// The Mac version of Chromium is built with PLATFORM(CG) while all other -// versions are PLATFORM(SKIA). We'll keep this Skia implementation here for -// common use and put the Mac implementation in webcursor_mac.mm. -void WebCursor::SetCustomData(WebCore::Image* image) { - if (!image) +#if WEBKIT_USING_SKIA +// The WEBKIT_USING_CG implementation is in webcursor_mac.mm. +void WebCursor::SetCustomData(const WebImage& image) { + if (image.isNull()) return; - WebCore::NativeImagePtr image_ptr = image->nativeImageForCurrentFrame(); - if (!image_ptr) + // Fill custom_data_ directly with the NativeImage pixels. + const SkBitmap& bitmap = image.getSkBitmap(); + SkAutoLockPixels bitmap_lock(bitmap); + custom_data_.resize(bitmap.getSize()); + memcpy(&custom_data_[0], bitmap.getPixels(), bitmap.getSize()); + custom_size_.set_width(bitmap.width()); + custom_size_.set_height(bitmap.height()); +} + +void WebCursor::ImageFromCustomData(WebImage* image) const { + if (custom_data_.empty()) return; - // Fill custom_data_ directly with the NativeImage pixels. - SkAutoLockPixels bitmap_lock(*image_ptr); - custom_data_.resize(image_ptr->getSize()); - memcpy(&custom_data_[0], image_ptr->getPixels(), image_ptr->getSize()); - custom_size_.set_width(image_ptr->width()); - custom_size_.set_height(image_ptr->height()); + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + custom_size_.width(), + custom_size_.height()); + if (!bitmap.allocPixels()) + return; + memcpy(bitmap.getPixels(), &custom_data_[0], custom_data_.size()); + + image->assign(bitmap); } #endif diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h index 8ecc9d0..86d693f 100644 --- a/webkit/glue/webcursor.h +++ b/webkit/glue/webcursor.h @@ -30,9 +30,9 @@ class NSCursor; class Pickle; -namespace WebCore { -class Image; -class PlatformCursor; +namespace WebKit { +class WebImage; +struct WebCursorInfo; } // This class encapsulates a cross-platform description of a cursor. Platform @@ -42,13 +42,17 @@ class PlatformCursor; class WebCursor { public: WebCursor(); - explicit WebCursor(const WebCore::PlatformCursor& platform_cursor); + explicit WebCursor(const WebKit::WebCursorInfo& cursor_info); ~WebCursor(); // Copy constructor/assignment operator combine. WebCursor(const WebCursor& other); const WebCursor& operator=(const WebCursor& other); + // Conversion from/to WebCursorInfo. + void InitFromCursorInfo(const WebKit::WebCursorInfo& cursor_info); + void GetCursorInfo(WebKit::WebCursorInfo* cursor_info) const; + // Serialization / De-serialization bool Deserialize(const Pickle* pickle, void** iter); bool Serialize(Pickle* pickle) const; @@ -110,7 +114,8 @@ class WebCursor { // Platform specific cleanup. void CleanupPlatformData(); - void SetCustomData(WebCore::Image* image); + void SetCustomData(const WebKit::WebImage& image); + void ImageFromCustomData(WebKit::WebImage* image) const; // WebCore::PlatformCursor type. int type_; diff --git a/webkit/glue/webcursor_gtk.cc b/webkit/glue/webcursor_gtk.cc index 77ced23..4c882ff 100644 --- a/webkit/glue/webcursor_gtk.cc +++ b/webkit/glue/webcursor_gtk.cc @@ -6,13 +6,10 @@ #include <gdk/gdk.h> -#include "config.h" -#include "PlatformCursor.h" - -#undef LOG #include "base/logging.h" +#include "webkit/api/public/WebCursorInfo.h" -using WebCore::PlatformCursor; +using WebKit::WebCursorInfo; namespace { @@ -48,87 +45,87 @@ GdkCursorType WebCursor::GetCursorType() const { // of the default X theme, but beware that the user's cursor theme can // change everything. switch (type_) { - case PlatformCursor::TypePointer: + case WebCursorInfo::TypePointer: return GDK_LAST_CURSOR; - case PlatformCursor::TypeCross: + case WebCursorInfo::TypeCross: return GDK_CROSS; - case PlatformCursor::TypeHand: + case WebCursorInfo::TypeHand: return GDK_HAND2; - case PlatformCursor::TypeIBeam: + case WebCursorInfo::TypeIBeam: return GDK_XTERM; - case PlatformCursor::TypeWait: + case WebCursorInfo::TypeWait: return GDK_WATCH; - case PlatformCursor::TypeHelp: + case WebCursorInfo::TypeHelp: return GDK_QUESTION_ARROW; - case PlatformCursor::TypeEastResize: + case WebCursorInfo::TypeEastResize: return GDK_RIGHT_SIDE; - case PlatformCursor::TypeNorthResize: + case WebCursorInfo::TypeNorthResize: return GDK_TOP_SIDE; - case PlatformCursor::TypeNorthEastResize: + case WebCursorInfo::TypeNorthEastResize: return GDK_TOP_RIGHT_CORNER; - case PlatformCursor::TypeNorthWestResize: + case WebCursorInfo::TypeNorthWestResize: return GDK_TOP_LEFT_CORNER; - case PlatformCursor::TypeSouthResize: + case WebCursorInfo::TypeSouthResize: return GDK_BOTTOM_SIDE; - case PlatformCursor::TypeSouthEastResize: + case WebCursorInfo::TypeSouthEastResize: return GDK_BOTTOM_RIGHT_CORNER; - case PlatformCursor::TypeSouthWestResize: + case WebCursorInfo::TypeSouthWestResize: return GDK_BOTTOM_LEFT_CORNER; - case PlatformCursor::TypeWestResize: + case WebCursorInfo::TypeWestResize: return GDK_LEFT_SIDE; - case PlatformCursor::TypeNorthSouthResize: + case WebCursorInfo::TypeNorthSouthResize: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeEastWestResize: + case WebCursorInfo::TypeEastWestResize: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNorthEastSouthWestResize: + case WebCursorInfo::TypeNorthEastSouthWestResize: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNorthWestSouthEastResize: + case WebCursorInfo::TypeNorthWestSouthEastResize: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeColumnResize: + case WebCursorInfo::TypeColumnResize: return GDK_SB_H_DOUBLE_ARROW; // TODO(evanm): is this correct? - case PlatformCursor::TypeRowResize: + case WebCursorInfo::TypeRowResize: return GDK_SB_V_DOUBLE_ARROW; // TODO(evanm): is this correct? - case PlatformCursor::TypeMiddlePanning: + case WebCursorInfo::TypeMiddlePanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeEastPanning: + case WebCursorInfo::TypeEastPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNorthPanning: + case WebCursorInfo::TypeNorthPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNorthEastPanning: + case WebCursorInfo::TypeNorthEastPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNorthWestPanning: + case WebCursorInfo::TypeNorthWestPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeSouthPanning: + case WebCursorInfo::TypeSouthPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeSouthEastPanning: + case WebCursorInfo::TypeSouthEastPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeSouthWestPanning: + case WebCursorInfo::TypeSouthWestPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeWestPanning: + case WebCursorInfo::TypeWestPanning: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeMove: + case WebCursorInfo::TypeMove: return GDK_FLEUR; - case PlatformCursor::TypeVerticalText: + case WebCursorInfo::TypeVerticalText: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeCell: + case WebCursorInfo::TypeCell: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeContextMenu: + case WebCursorInfo::TypeContextMenu: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeAlias: + case WebCursorInfo::TypeAlias: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeProgress: + case WebCursorInfo::TypeProgress: return GDK_WATCH; - case PlatformCursor::TypeNoDrop: + case WebCursorInfo::TypeNoDrop: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeCopy: + case WebCursorInfo::TypeCopy: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNone: + case WebCursorInfo::TypeNone: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeNotAllowed: + case WebCursorInfo::TypeNotAllowed: NOTIMPLEMENTED(); return GDK_LAST_CURSOR; - case PlatformCursor::TypeZoomIn: - case PlatformCursor::TypeZoomOut: - case PlatformCursor::TypeCustom: + case WebCursorInfo::TypeZoomIn: + case WebCursorInfo::TypeZoomOut: + case WebCursorInfo::TypeCustom: return GDK_CURSOR_IS_PIXMAP; } NOTREACHED(); @@ -137,13 +134,13 @@ GdkCursorType WebCursor::GetCursorType() const { GdkCursor* WebCursor::GetCustomCursor() const { switch (type_) { - case PlatformCursor::TypeZoomIn: + case WebCursorInfo::TypeZoomIn: return GetInlineCustomCursor(CustomCursorZoomIn); - case PlatformCursor::TypeZoomOut: + case WebCursorInfo::TypeZoomOut: return GetInlineCustomCursor(CustomCursorZoomOut); } - if (type_ != PlatformCursor::TypeCustom) { + if (type_ != WebCursorInfo::TypeCustom) { NOTREACHED(); return NULL; } diff --git a/webkit/glue/webcursor_mac.mm b/webkit/glue/webcursor_mac.mm index 90ff096..0b06df8 100644 --- a/webkit/glue/webcursor_mac.mm +++ b/webkit/glue/webcursor_mac.mm @@ -6,14 +6,15 @@ #import <AppKit/AppKit.h> -#include "config.h" -#include "PlatformCursor.h" -#include "RetainPtr.h" - -#undef LOG #include "base/logging.h" +#include "base/scoped_cftyperef.h" +#include "webkit/api/public/WebCursorInfo.h" +#include "webkit/api/public/WebImage.h" +#include "webkit/api/public/WebSize.h" -using WebCore::PlatformCursor; +using WebKit::WebCursorInfo; +using WebKit::WebImage; +using WebKit::WebSize; namespace { @@ -27,149 +28,169 @@ NSCursor* LoadCursor(const char* name, int x, int y) { hotSpot:NSMakePoint(x, y)] autorelease]; } +CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data, + const gfx::Size& custom_size) { + scoped_cftyperef<CGColorSpaceRef> cg_color(CGColorSpaceCreateDeviceRGB()); + // this is safe since we're not going to draw into the context we're creating + void* data = const_cast<char*>(&custom_data[0]); + // settings here match SetCustomData() below; keep in sync + scoped_cftyperef<CGContextRef> context( + CGBitmapContextCreate(data, + custom_size.width(), + custom_size.height(), + 8, + custom_size.width()*4, + cg_color.get(), + kCGImageAlphaPremultipliedLast | + kCGBitmapByteOrder32Big)); + return CGBitmapContextCreateImage(context.get()); +} + NSCursor* CreateCustomCursor(const std::vector<char>& custom_data, const gfx::Size& custom_size, const gfx::Point& hotspot) { - RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB()); - // this is safe since we're not going to draw into the context we're creating - void* data = const_cast<void *>(static_cast<const void*>(&custom_data[0])); - // settings here match SetCustomData() below; keep in sync - RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate( - data, - custom_size.width(), - custom_size.height(), - 8, - custom_size.width()*4, - cg_color.get(), - kCGImageAlphaPremultipliedLast | - kCGBitmapByteOrder32Big)); - RetainPtr<CGImage> cg_image(AdoptCF, - CGBitmapContextCreateImage(context.get())); - - RetainPtr<NSBitmapImageRep> ns_bitmap( - AdoptNS, [[NSBitmapImageRep alloc] initWithCGImage:cg_image.get()]); - RetainPtr<NSImage> cursor_image([[NSImage alloc] init]); - [cursor_image.get() addRepresentation:ns_bitmap.get()]; + scoped_cftyperef<CGImageRef> cg_image( + CreateCGImageFromCustomData(custom_data, custom_size)); + + NSBitmapImageRep* ns_bitmap = + [[NSBitmapImageRep alloc] initWithCGImage:cg_image.get()]; + NSImage* cursor_image = [[NSImage alloc] init]; DCHECK(cursor_image); - return [[[NSCursor alloc] initWithImage:cursor_image.get() - hotSpot:NSMakePoint(hotspot.x(), - hotspot.y())] - autorelease]; -} + [cursor_image addRepresentation:ns_bitmap]; + [ns_bitmap release]; + + NSCursor* cursor = [[NSCursor alloc] initWithImage:cursor_image + hotSpot:NSMakePoint(hotspot.x(), + hotspot.y())]; + [cursor_image release]; + return [cursor autorelease]; } +} // namespace + // We're matching Safari's cursor choices; see platform/mac/CursorMac.mm NSCursor* WebCursor::GetCursor() const { switch (type_) { - case PlatformCursor::TypePointer: + case WebCursorInfo::TypePointer: return [NSCursor arrowCursor]; - case PlatformCursor::TypeCross: + case WebCursorInfo::TypeCross: return LoadCursor("crossHairCursor", 11, 11); - case PlatformCursor::TypeHand: + case WebCursorInfo::TypeHand: return LoadCursor("linkCursor", 6, 1); - case PlatformCursor::TypeIBeam: + case WebCursorInfo::TypeIBeam: return [NSCursor IBeamCursor]; - case PlatformCursor::TypeWait: + case WebCursorInfo::TypeWait: return LoadCursor("waitCursor", 7, 7); - case PlatformCursor::TypeHelp: + case WebCursorInfo::TypeHelp: return LoadCursor("helpCursor", 8, 8); - case PlatformCursor::TypeEastResize: - case PlatformCursor::TypeEastPanning: + case WebCursorInfo::TypeEastResize: + case WebCursorInfo::TypeEastPanning: return LoadCursor("eastResizeCursor", 14, 7); - case PlatformCursor::TypeNorthResize: - case PlatformCursor::TypeNorthPanning: + case WebCursorInfo::TypeNorthResize: + case WebCursorInfo::TypeNorthPanning: return LoadCursor("northResizeCursor", 7, 1); - case PlatformCursor::TypeNorthEastResize: - case PlatformCursor::TypeNorthEastPanning: + case WebCursorInfo::TypeNorthEastResize: + case WebCursorInfo::TypeNorthEastPanning: return LoadCursor("northEastResizeCursor", 14, 1); - case PlatformCursor::TypeNorthWestResize: - case PlatformCursor::TypeNorthWestPanning: + case WebCursorInfo::TypeNorthWestResize: + case WebCursorInfo::TypeNorthWestPanning: return LoadCursor("northWestResizeCursor", 0, 0); - case PlatformCursor::TypeSouthResize: - case PlatformCursor::TypeSouthPanning: + case WebCursorInfo::TypeSouthResize: + case WebCursorInfo::TypeSouthPanning: return LoadCursor("southResizeCursor", 7, 14); - case PlatformCursor::TypeSouthEastResize: - case PlatformCursor::TypeSouthEastPanning: + case WebCursorInfo::TypeSouthEastResize: + case WebCursorInfo::TypeSouthEastPanning: return LoadCursor("southEastResizeCursor", 14, 14); - case PlatformCursor::TypeSouthWestResize: - case PlatformCursor::TypeSouthWestPanning: + case WebCursorInfo::TypeSouthWestResize: + case WebCursorInfo::TypeSouthWestPanning: return LoadCursor("southWestResizeCursor", 1, 14); - case PlatformCursor::TypeWestResize: - case PlatformCursor::TypeWestPanning: + case WebCursorInfo::TypeWestResize: + case WebCursorInfo::TypeWestPanning: return LoadCursor("westResizeCursor", 1, 7); - case PlatformCursor::TypeNorthSouthResize: + case WebCursorInfo::TypeNorthSouthResize: return LoadCursor("northSouthResizeCursor", 7, 7); - case PlatformCursor::TypeEastWestResize: + case WebCursorInfo::TypeEastWestResize: return LoadCursor("eastWestResizeCursor", 7, 7); - case PlatformCursor::TypeNorthEastSouthWestResize: + case WebCursorInfo::TypeNorthEastSouthWestResize: return LoadCursor("northEastSouthWestResizeCursor", 7, 7); - case PlatformCursor::TypeNorthWestSouthEastResize: + case WebCursorInfo::TypeNorthWestSouthEastResize: return LoadCursor("northWestSouthEastResizeCursor", 7, 7); - case PlatformCursor::TypeColumnResize: + case WebCursorInfo::TypeColumnResize: return [NSCursor resizeLeftRightCursor]; - case PlatformCursor::TypeRowResize: + case WebCursorInfo::TypeRowResize: return [NSCursor resizeUpDownCursor]; - case PlatformCursor::TypeMiddlePanning: - case PlatformCursor::TypeMove: + case WebCursorInfo::TypeMiddlePanning: + case WebCursorInfo::TypeMove: return LoadCursor("moveCursor", 7, 7); - case PlatformCursor::TypeVerticalText: + case WebCursorInfo::TypeVerticalText: return LoadCursor("verticalTextCursor", 7, 7); - case PlatformCursor::TypeCell: + case WebCursorInfo::TypeCell: return LoadCursor("cellCursor", 7, 7); - case PlatformCursor::TypeContextMenu: + case WebCursorInfo::TypeContextMenu: return LoadCursor("contextMenuCursor", 3, 2); - case PlatformCursor::TypeAlias: + case WebCursorInfo::TypeAlias: return LoadCursor("aliasCursor", 11, 3); - case PlatformCursor::TypeProgress: + case WebCursorInfo::TypeProgress: return LoadCursor("progressCursor", 3, 2); - case PlatformCursor::TypeNoDrop: + case WebCursorInfo::TypeNoDrop: return LoadCursor("noDropCursor", 3, 1); - case PlatformCursor::TypeCopy: + case WebCursorInfo::TypeCopy: return LoadCursor("copyCursor", 3, 2); - case PlatformCursor::TypeNone: + case WebCursorInfo::TypeNone: return LoadCursor("noneCursor", 7, 7); - case PlatformCursor::TypeNotAllowed: + case WebCursorInfo::TypeNotAllowed: return LoadCursor("notAllowedCursor", 11, 11); - case PlatformCursor::TypeZoomIn: + case WebCursorInfo::TypeZoomIn: return LoadCursor("zoomInCursor", 7, 7); - case PlatformCursor::TypeZoomOut: + case WebCursorInfo::TypeZoomOut: return LoadCursor("zoomOutCursor", 7, 7); - case PlatformCursor::TypeCustom: + case WebCursorInfo::TypeCustom: return CreateCustomCursor(custom_data_, custom_size_, hotspot_); } NOTREACHED(); return nil; } -void WebCursor::SetCustomData(WebCore::Image* image) { - WebCore::NativeImagePtr image_ptr = image->nativeImageForCurrentFrame(); - if (!image_ptr) +void WebCursor::SetCustomData(const WebImage& image) { + if (image.isNull()) return; - RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB()); + scoped_cftyperef<CGColorSpaceRef> cg_color( + CGColorSpaceCreateDeviceRGB()); + + const WebSize& image_dimensions = image.size(); + int image_width = image_dimensions.width; + int image_height = image_dimensions.height; - size_t size = CGImageGetHeight(image_ptr)*CGImageGetWidth(image_ptr)*4; + size_t size = image_height * image_width * 4; custom_data_.resize(size); - custom_size_.set_width(CGImageGetWidth(image_ptr)); - custom_size_.set_height(CGImageGetHeight(image_ptr)); + custom_size_.set_width(image_width); + custom_size_.set_height(image_height); // These settings match up with the code in CreateCustomCursor() above; keep // them in sync. // TODO(avi): test to ensure that the flags here are correct for RGBA - RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate( - &custom_data_[0], - CGImageGetWidth(image_ptr), - CGImageGetHeight(image_ptr), - 8, - CGImageGetWidth(image_ptr)*4, - cg_color.get(), - kCGImageAlphaPremultipliedLast | - kCGBitmapByteOrder32Big)); - CGRect rect = CGRectMake(0, 0, - CGImageGetWidth(image_ptr), - CGImageGetHeight(image_ptr)); - CGContextDrawImage(context.get(), rect, image_ptr); + scoped_cftyperef<CGContextRef> context( + CGBitmapContextCreate(&custom_data_[0], + image_width, + image_height, + 8, + image_width * 4, + cg_color.get(), + kCGImageAlphaPremultipliedLast | + kCGBitmapByteOrder32Big)); + CGRect rect = CGRectMake(0, 0, image_width, image_height); + CGContextDrawImage(context.get(), rect, image.getCGImageRef()); +} + +void WebCursor::ImageFromCustomData(WebImage* image) const { + if (custom_data_.empty()) + return; + + scoped_cftyperef<CGImageRef> cg_image( + CreateCGImageFromCustomData(custom_data_, custom_size_)); + *image = cg_image.get(); } void WebCursor::InitPlatformData() { diff --git a/webkit/glue/webcursor_win.cc b/webkit/glue/webcursor_win.cc index 02cb52e..c1d7556 100644 --- a/webkit/glue/webcursor_win.cc +++ b/webkit/glue/webcursor_win.cc @@ -2,103 +2,99 @@ // source code is governed by a BSD-style license that can be found in the // LICENSE file. -#include "config.h" -#include "NativeImageSkia.h" -#include "PlatformCursor.h" - -#undef LOG #include "base/gfx/gdi_util.h" #include "base/logging.h" #include "base/pickle.h" #include "grit/webkit_resources.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/glue/webcursor.h" -using WebCore::PlatformCursor; +using WebKit::WebCursorInfo; -static LPCWSTR ToCursorID(PlatformCursor::Type type) { +static LPCWSTR ToCursorID(WebCursorInfo::Type type) { switch (type) { - case PlatformCursor::TypePointer: + case WebCursorInfo::TypePointer: return IDC_ARROW; - case PlatformCursor::TypeCross: + case WebCursorInfo::TypeCross: return IDC_CROSS; - case PlatformCursor::TypeHand: + case WebCursorInfo::TypeHand: return IDC_HAND; - case PlatformCursor::TypeIBeam: + case WebCursorInfo::TypeIBeam: return IDC_IBEAM; - case PlatformCursor::TypeWait: + case WebCursorInfo::TypeWait: return IDC_WAIT; - case PlatformCursor::TypeHelp: + case WebCursorInfo::TypeHelp: return IDC_HELP; - case PlatformCursor::TypeEastResize: + case WebCursorInfo::TypeEastResize: return IDC_SIZEWE; - case PlatformCursor::TypeNorthResize: + case WebCursorInfo::TypeNorthResize: return IDC_SIZENS; - case PlatformCursor::TypeNorthEastResize: + case WebCursorInfo::TypeNorthEastResize: return IDC_SIZENESW; - case PlatformCursor::TypeNorthWestResize: + case WebCursorInfo::TypeNorthWestResize: return IDC_SIZENWSE; - case PlatformCursor::TypeSouthResize: + case WebCursorInfo::TypeSouthResize: return IDC_SIZENS; - case PlatformCursor::TypeSouthEastResize: + case WebCursorInfo::TypeSouthEastResize: return IDC_SIZENWSE; - case PlatformCursor::TypeSouthWestResize: + case WebCursorInfo::TypeSouthWestResize: return IDC_SIZENESW; - case PlatformCursor::TypeWestResize: + case WebCursorInfo::TypeWestResize: return IDC_SIZEWE; - case PlatformCursor::TypeNorthSouthResize: + case WebCursorInfo::TypeNorthSouthResize: return IDC_SIZENS; - case PlatformCursor::TypeEastWestResize: + case WebCursorInfo::TypeEastWestResize: return IDC_SIZEWE; - case PlatformCursor::TypeNorthEastSouthWestResize: + case WebCursorInfo::TypeNorthEastSouthWestResize: return IDC_SIZENESW; - case PlatformCursor::TypeNorthWestSouthEastResize: + case WebCursorInfo::TypeNorthWestSouthEastResize: return IDC_SIZENWSE; - case PlatformCursor::TypeColumnResize: + case WebCursorInfo::TypeColumnResize: return MAKEINTRESOURCE(IDC_COLRESIZE); - case PlatformCursor::TypeRowResize: + case WebCursorInfo::TypeRowResize: return MAKEINTRESOURCE(IDC_ROWRESIZE); - case PlatformCursor::TypeMiddlePanning: + case WebCursorInfo::TypeMiddlePanning: return MAKEINTRESOURCE(IDC_PAN_MIDDLE); - case PlatformCursor::TypeEastPanning: + case WebCursorInfo::TypeEastPanning: return MAKEINTRESOURCE(IDC_PAN_EAST); - case PlatformCursor::TypeNorthPanning: + case WebCursorInfo::TypeNorthPanning: return MAKEINTRESOURCE(IDC_PAN_NORTH); - case PlatformCursor::TypeNorthEastPanning: + case WebCursorInfo::TypeNorthEastPanning: return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST); - case PlatformCursor::TypeNorthWestPanning: + case WebCursorInfo::TypeNorthWestPanning: return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST); - case PlatformCursor::TypeSouthPanning: + case WebCursorInfo::TypeSouthPanning: return MAKEINTRESOURCE(IDC_PAN_SOUTH); - case PlatformCursor::TypeSouthEastPanning: + case WebCursorInfo::TypeSouthEastPanning: return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST); - case PlatformCursor::TypeSouthWestPanning: + case WebCursorInfo::TypeSouthWestPanning: return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST); - case PlatformCursor::TypeWestPanning: + case WebCursorInfo::TypeWestPanning: return MAKEINTRESOURCE(IDC_PAN_WEST); - case PlatformCursor::TypeMove: + case WebCursorInfo::TypeMove: return IDC_SIZEALL; - case PlatformCursor::TypeVerticalText: + case WebCursorInfo::TypeVerticalText: return MAKEINTRESOURCE(IDC_VERTICALTEXT); - case PlatformCursor::TypeCell: + case WebCursorInfo::TypeCell: return MAKEINTRESOURCE(IDC_CELL); - case PlatformCursor::TypeContextMenu: + case WebCursorInfo::TypeContextMenu: return MAKEINTRESOURCE(IDC_ARROW); - case PlatformCursor::TypeAlias: + case WebCursorInfo::TypeAlias: return MAKEINTRESOURCE(IDC_ALIAS); - case PlatformCursor::TypeProgress: + case WebCursorInfo::TypeProgress: return IDC_APPSTARTING; - case PlatformCursor::TypeNoDrop: + case WebCursorInfo::TypeNoDrop: return IDC_NO; - case PlatformCursor::TypeCopy: + case WebCursorInfo::TypeCopy: return MAKEINTRESOURCE(IDC_COPYCUR); - case PlatformCursor::TypeNone: + case WebCursorInfo::TypeNone: return IDC_ARROW; - case PlatformCursor::TypeNotAllowed: + case WebCursorInfo::TypeNotAllowed: return IDC_NO; - case PlatformCursor::TypeZoomIn: + case WebCursorInfo::TypeZoomIn: return MAKEINTRESOURCE(IDC_ZOOMIN); - case PlatformCursor::TypeZoomOut: + case WebCursorInfo::TypeZoomOut: return MAKEINTRESOURCE(IDC_ZOOMOUT); } NOTREACHED(); @@ -109,36 +105,36 @@ static bool IsSystemCursorID(LPCWSTR cursor_id) { return cursor_id >= IDC_ARROW; // See WinUser.h } -static PlatformCursor::Type ToPlatformCursorType(HCURSOR cursor) { +static WebCursorInfo::Type ToCursorType(HCURSOR cursor) { static struct { HCURSOR cursor; - PlatformCursor::Type type; + WebCursorInfo::Type type; } kStandardCursors[] = { - { LoadCursor(NULL, IDC_ARROW), PlatformCursor::TypePointer }, - { LoadCursor(NULL, IDC_IBEAM), PlatformCursor::TypeIBeam }, - { LoadCursor(NULL, IDC_WAIT), PlatformCursor::TypeWait }, - { LoadCursor(NULL, IDC_CROSS), PlatformCursor::TypeCross }, - { LoadCursor(NULL, IDC_SIZENWSE), PlatformCursor::TypeNorthWestResize }, - { LoadCursor(NULL, IDC_SIZENESW), PlatformCursor::TypeNorthEastResize }, - { LoadCursor(NULL, IDC_SIZEWE), PlatformCursor::TypeEastWestResize }, - { LoadCursor(NULL, IDC_SIZENS), PlatformCursor::TypeNorthSouthResize }, - { LoadCursor(NULL, IDC_SIZEALL), PlatformCursor::TypeMove }, - { LoadCursor(NULL, IDC_NO), PlatformCursor::TypeNotAllowed }, - { LoadCursor(NULL, IDC_HAND), PlatformCursor::TypeHand }, - { LoadCursor(NULL, IDC_APPSTARTING), PlatformCursor::TypeProgress }, - { LoadCursor(NULL, IDC_HELP), PlatformCursor::TypeHelp }, + { LoadCursor(NULL, IDC_ARROW), WebCursorInfo::TypePointer }, + { LoadCursor(NULL, IDC_IBEAM), WebCursorInfo::TypeIBeam }, + { LoadCursor(NULL, IDC_WAIT), WebCursorInfo::TypeWait }, + { LoadCursor(NULL, IDC_CROSS), WebCursorInfo::TypeCross }, + { LoadCursor(NULL, IDC_SIZENWSE), WebCursorInfo::TypeNorthWestResize }, + { LoadCursor(NULL, IDC_SIZENESW), WebCursorInfo::TypeNorthEastResize }, + { LoadCursor(NULL, IDC_SIZEWE), WebCursorInfo::TypeEastWestResize }, + { LoadCursor(NULL, IDC_SIZENS), WebCursorInfo::TypeNorthSouthResize }, + { LoadCursor(NULL, IDC_SIZEALL), WebCursorInfo::TypeMove }, + { LoadCursor(NULL, IDC_NO), WebCursorInfo::TypeNotAllowed }, + { LoadCursor(NULL, IDC_HAND), WebCursorInfo::TypeHand }, + { LoadCursor(NULL, IDC_APPSTARTING), WebCursorInfo::TypeProgress }, + { LoadCursor(NULL, IDC_HELP), WebCursorInfo::TypeHelp }, }; for (int i = 0; i < arraysize(kStandardCursors); i++) { if (cursor == kStandardCursors[i].cursor) return kStandardCursors[i].type; } - return PlatformCursor::TypeCustom; + return WebCursorInfo::TypeCustom; } HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ if (!IsCustom()) { const wchar_t* cursor_id = - ToCursorID(static_cast<PlatformCursor::Type>(type_)); + ToCursorID(static_cast<WebCursorInfo::Type>(type_)); if (IsSystemCursorID(cursor_id)) module_handle = NULL; @@ -190,13 +186,12 @@ HCURSOR WebCursor::GetCursor(HINSTANCE module_handle){ } void WebCursor::InitFromExternalCursor(HCURSOR cursor) { - WebCore::PlatformCursor::Type cursor_type = ToPlatformCursorType(cursor); + WebCursorInfo::Type cursor_type = ToCursorType(cursor); - *this = WebCursor(cursor_type); + InitFromCursorInfo(WebCursorInfo(cursor_type)); - if (cursor_type == WebCore::PlatformCursor::TypeCustom) { + if (cursor_type == WebCursorInfo::TypeCustom) external_cursor_ = cursor; - } } void WebCursor::InitPlatformData() { diff --git a/webkit/glue/webplugin_delegate.h b/webkit/glue/webplugin_delegate.h index 7d0fa88..92e4b42 100644 --- a/webkit/glue/webplugin_delegate.h +++ b/webkit/glue/webplugin_delegate.h @@ -15,12 +15,12 @@ struct NPObject; class FilePath; class GURL; -class WebCursor; class WebPlugin; class WebPluginResourceClient; namespace WebKit { class WebInputEvent; +struct WebCursorInfo; } namespace gfx { @@ -88,7 +88,7 @@ class WebPluginDelegate { // For windowless plugins, gives them a user event like mouse/keyboard. // Returns whether the event was handled. virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, - WebCursor* cursor) = 0; + WebKit::WebCursorInfo* cursor) = 0; // Gets the NPObject associated with the plugin for scripting. virtual NPObject* GetPluginScriptableObject() = 0; diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index e554255..157ecf3 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -4,7 +4,6 @@ #include "config.h" -#include "Cursor.h" #include "Document.h" #include "DocumentLoader.h" #include "Event.h" @@ -48,6 +47,7 @@ #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "net/base/escape.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebData.h" #include "webkit/api/public/WebHTTPBody.h" #include "webkit/api/public/WebInputEvent.h" @@ -62,7 +62,6 @@ #include "webkit/glue/event_conversion.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/multipart_response_delegate.h" -#include "webkit/glue/webcursor.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webplugin_impl.h" #include "webkit/glue/plugins/plugin_host.h" @@ -72,6 +71,7 @@ #include "webkit/glue/webview_impl.h" #include "googleurl/src/gurl.h" +using WebKit::WebCursorInfo; using WebKit::WebData; using WebKit::WebHTTPBody; using WebKit::WebInputEvent; @@ -878,8 +878,8 @@ void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) { // TODO(pkasting): http://b/1119691 This conditional seems exactly backwards, // but it matches Safari's code, and if I reverse it, giving focus to a // transparent (windowless) plugin fails. - WebCursor cursor; - if (!delegate_->HandleInputEvent(web_event, &cursor)) + WebCursorInfo cursor_info; + if (!delegate_->HandleInputEvent(web_event, &cursor_info)) event->setDefaultHandled(); WebCore::Page* page = parent_view->frame()->page(); @@ -892,7 +892,7 @@ void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) { // A windowless plugin can change the cursor in response to the WM_MOUSEMOVE // event. We need to reflect the changed cursor in the frame view as the // mouse is moved in the boundaries of the windowless plugin. - chrome_client->SetCursorForPlugin(cursor); + chrome_client->SetCursorForPlugin(cursor_info); } void WebPluginImpl::handleKeyboardEvent(WebCore::KeyboardEvent* event) { @@ -900,8 +900,8 @@ void WebPluginImpl::handleKeyboardEvent(WebCore::KeyboardEvent* event) { if (!ToWebKeyboardEvent(*event, &web_event)) return; // TODO(pkasting): http://b/1119691 See above. - WebCursor current_web_cursor; - if (!delegate_->HandleInputEvent(web_event, ¤t_web_cursor)) + WebCursorInfo cursor_info; + if (!delegate_->HandleInputEvent(web_event, &cursor_info)) event->setDefaultHandled(); } diff --git a/webkit/glue/webwidget_delegate.h b/webkit/glue/webwidget_delegate.h index 0e27374..faca629 100644 --- a/webkit/glue/webwidget_delegate.h +++ b/webkit/glue/webwidget_delegate.h @@ -12,12 +12,12 @@ #include "webkit/glue/window_open_disposition.h" namespace WebKit { +struct WebCursorInfo; struct WebRect; struct WebScreenInfo; } class WebWidget; -class WebCursor; struct WebPluginGeometry; struct WebMenuItem { @@ -88,7 +88,8 @@ class WebWidgetDelegate { virtual void Blur(WebWidget* webwidget) = 0; virtual void SetCursor(WebWidget* webwidget, - const WebCursor& cursor) = 0; + const WebKit::WebCursorInfo& cursor) = 0; + // Returns the rectangle of the WebWidget in screen coordinates. virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect) = 0; diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc index 625f0d8..bfe27ac 100644 --- a/webkit/glue/webworker_impl.cc +++ b/webkit/glue/webworker_impl.cc @@ -33,10 +33,11 @@ #include "webkit/glue/webview_delegate.h" #include "webkit/glue/webworker_impl.h" -using WebKit::WebWorker; -using WebKit::WebWorkerClient; +using WebKit::WebCursorInfo; using WebKit::WebString; using WebKit::WebURL; +using WebKit::WebWorker; +using WebKit::WebWorkerClient; #if ENABLE(WORKERS) @@ -69,7 +70,7 @@ class WorkerWebViewDelegate : public WebViewDelegate { virtual void GetWindowRect(WebWidget *webwidget, WebKit::WebRect *rect) { } virtual bool IsHidden(WebWidget *webwidget) { return true; } virtual void RunModal(WebWidget *webwidget) { } - virtual void SetCursor(WebWidget *webwidget, const WebCursor &cursor) { } + virtual void SetCursor(WebWidget *webwidget, const WebCursorInfo &cursor) { } virtual void SetWindowRect(WebWidget *webwidget, const WebKit::WebRect &rect) { } virtual void Show(WebWidget *webwidget, WindowOpenDisposition disposition) { } diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm index 414ac6d..93a3032 100644 --- a/webkit/tools/test_shell/mac/test_webview_delegate.mm +++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm @@ -7,6 +7,7 @@ #import <Cocoa/Cocoa.h> #include "base/string_util.h" #include "base/sys_string_conversions.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebRect.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webview.h" @@ -15,6 +16,7 @@ #include "webkit/glue/webmenurunner_mac.h" #include "webkit/tools/test_shell/test_shell.h" +using WebKit::WebCursorInfo; using WebKit::WebRect; // WebViewDelegate ----------------------------------------------------------- @@ -123,8 +125,8 @@ void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { } void TestWebViewDelegate::SetCursor(WebWidget* webwidget, - const WebCursor& cursor) { - NSCursor* ns_cursor = cursor.GetCursor(); + const WebCursorInfo& cursor_info) { + NSCursor* ns_cursor = WebCursor(cursor_info).GetCursor(); [ns_cursor set]; } diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 221943e..4c0f079 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -237,7 +237,7 @@ class TestWebViewDelegate : public base::RefCounted<TestWebViewDelegate>, virtual void Focus(WebWidget* webwidget); virtual void Blur(WebWidget* webwidget); virtual void SetCursor(WebWidget* webwidget, - const WebCursor& cursor); + const WebKit::WebCursorInfo& cursor); virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect); virtual void SetWindowRect(WebWidget* webwidget, const WebKit::WebRect& rect); diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc index a05eefd..46ecc9d 100644 --- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc +++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc @@ -15,6 +15,7 @@ #include "base/string_util.h" #include "net/base/net_errors.h" #include "chrome/common/page_transition_types.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebRect.h" #include "webkit/glue/webcursor.h" #include "webkit/glue/webdropdata.h" @@ -30,6 +31,7 @@ #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" +using WebKit::WebCursorInfo; using WebKit::WebRect; namespace { @@ -145,8 +147,8 @@ void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { } void TestWebViewDelegate::SetCursor(WebWidget* webwidget, - const WebCursor& cursor) { - current_cursor_ = cursor; + const WebCursorInfo& cursor_info) { + current_cursor_.InitFromCursorInfo(cursor_info); GdkCursorType cursor_type = current_cursor_.GetCursorType(); GdkCursor* gdk_cursor; if (cursor_type == GDK_CURSOR_IS_PIXMAP) { diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc index a0f3254..c0dbc825 100644 --- a/webkit/tools/test_shell/test_webview_delegate_win.cc +++ b/webkit/tools/test_shell/test_webview_delegate_win.cc @@ -19,6 +19,7 @@ #include "base/string_util.h" #include "base/trace_event.h" #include "net/base/net_errors.h" +#include "webkit/api/public/WebCursorInfo.h" #include "webkit/api/public/WebRect.h" #include "webkit/glue/webdropdata.h" #include "webkit/glue/webframe.h" @@ -34,6 +35,7 @@ #include "webkit/tools/test_shell/test_navigation_controller.h" #include "webkit/tools/test_shell/test_shell.h" +using WebKit::WebCursorInfo; using WebKit::WebRect; // WebViewDelegate ----------------------------------------------------------- @@ -97,9 +99,9 @@ void TestWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) { } void TestWebViewDelegate::SetCursor(WebWidget* webwidget, - const WebCursor& cursor) { + const WebCursorInfo& cursor_info) { if (WebWidgetHost* host = GetHostForWidget(webwidget)) { - current_cursor_ = cursor; + current_cursor_.InitFromCursorInfo(cursor_info); HINSTANCE mod_handle = GetModuleHandle(NULL); host->SetCursor(current_cursor_.GetCursor(mod_handle)); } diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 98896d0..63017f24 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -4217,6 +4217,7 @@ 'api/public/WebCommon.h', 'api/public/WebConsoleMessage.h', 'api/public/WebCString.h', + 'api/public/WebCursorInfo.h', 'api/public/WebData.h', 'api/public/WebDataSource.h', 'api/public/WebDragData.h', @@ -4265,6 +4266,7 @@ 'api/src/TemporaryGlue.h', 'api/src/WebCache.cpp', 'api/src/WebCString.cpp', + 'api/src/WebCursorInfo.cpp', 'api/src/WebData.cpp', 'api/src/WebDragData.cpp', 'api/src/WebForm.cpp', |