diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-03 21:14:36 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-03 21:14:36 +0000 |
commit | c78395583ae96c6ad4287cc1af8ec2ba1cd038c8 (patch) | |
tree | 7d3190a78c9c6b243ab5ea6a1c12090835edc3f4 /webkit | |
parent | 741a46a76bd8f09547a3ea8967f380ccde31ae65 (diff) | |
download | chromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.zip chromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.tar.gz chromium_src-c78395583ae96c6ad4287cc1af8ec2ba1cd038c8.tar.bz2 |
aura-x11: Add custom web cursor support.
BUG=102562
TEST=manually (using sites that use custom cursor, e.g.: http://beradrian.users.sourceforge.net/articles/cursor.html)
Review URL: https://chromiumcodereview.appspot.com/9463003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130456 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webcursor.h | 9 | ||||
-rw-r--r-- | webkit/glue/webcursor_aura.cc | 116 | ||||
-rw-r--r-- | webkit/glue/webcursor_aurawin.cc | 35 | ||||
-rw-r--r-- | webkit/glue/webcursor_aurax11.cc | 83 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 7 |
5 files changed, 181 insertions, 69 deletions
diff --git a/webkit/glue/webcursor.h b/webkit/glue/webcursor.h index 0dfddcf..23d55fe 100644 --- a/webkit/glue/webcursor.h +++ b/webkit/glue/webcursor.h @@ -71,7 +71,9 @@ class WEBKIT_GLUE_EXPORT WebCursor { // Returns a native cursor representing the current WebCursor instance. gfx::NativeCursor GetNativeCursor(); -#if defined(OS_WIN) && !defined(USE_AURA) +#if defined(USE_AURA) + const ui::PlatformCursor GetPlatformCursor(); +#elif defined(OS_WIN) // Returns a HCURSOR representing the current WebCursor instance. // The ownership of the HCURSOR (does not apply to external cursors) remains // with the WebCursor instance. @@ -143,7 +145,10 @@ class WEBKIT_GLUE_EXPORT WebCursor { gfx::Size custom_size_; std::vector<char> custom_data_; -#if defined(OS_WIN) +#if defined(USE_AURA) && defined(USE_X11) + // Only used for custom cursors. + ui::PlatformCursor platform_cursor_; +#elif defined(OS_WIN) // An externally generated HCURSOR. We assume that it remains valid, i.e we // don't attempt to copy the HCURSOR. HCURSOR external_cursor_; diff --git a/webkit/glue/webcursor_aura.cc b/webkit/glue/webcursor_aura.cc index 08719c1..2642c47 100644 --- a/webkit/glue/webcursor_aura.cc +++ b/webkit/glue/webcursor_aura.cc @@ -6,123 +6,105 @@ #include "base/logging.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" -#include "ui/aura/cursor.h" +#include "ui/base/cursor/cursor.h" using WebKit::WebCursorInfo; gfx::NativeCursor WebCursor::GetNativeCursor() { switch (type_) { case WebCursorInfo::TypePointer: - return aura::kCursorPointer; + return ui::kCursorPointer; case WebCursorInfo::TypeCross: - return aura::kCursorCross; + return ui::kCursorCross; case WebCursorInfo::TypeHand: - return aura::kCursorHand; + return ui::kCursorHand; case WebCursorInfo::TypeIBeam: - return aura::kCursorIBeam; + return ui::kCursorIBeam; case WebCursorInfo::TypeWait: - return aura::kCursorWait; + return ui::kCursorWait; case WebCursorInfo::TypeHelp: - return aura::kCursorHelp; + return ui::kCursorHelp; case WebCursorInfo::TypeEastResize: - return aura::kCursorEastResize; + return ui::kCursorEastResize; case WebCursorInfo::TypeNorthResize: - return aura::kCursorNorthResize; + return ui::kCursorNorthResize; case WebCursorInfo::TypeNorthEastResize: - return aura::kCursorNorthEastResize; + return ui::kCursorNorthEastResize; case WebCursorInfo::TypeNorthWestResize: - return aura::kCursorNorthWestResize; + return ui::kCursorNorthWestResize; case WebCursorInfo::TypeSouthResize: - return aura::kCursorSouthResize; + return ui::kCursorSouthResize; case WebCursorInfo::TypeSouthEastResize: - return aura::kCursorSouthEastResize; + return ui::kCursorSouthEastResize; case WebCursorInfo::TypeSouthWestResize: - return aura::kCursorSouthWestResize; + return ui::kCursorSouthWestResize; case WebCursorInfo::TypeWestResize: - return aura::kCursorWestResize; + return ui::kCursorWestResize; case WebCursorInfo::TypeNorthSouthResize: - return aura::kCursorNorthSouthResize; + return ui::kCursorNorthSouthResize; case WebCursorInfo::TypeEastWestResize: - return aura::kCursorEastWestResize; + return ui::kCursorEastWestResize; case WebCursorInfo::TypeNorthEastSouthWestResize: - return aura::kCursorNorthEastSouthWestResize; + return ui::kCursorNorthEastSouthWestResize; case WebCursorInfo::TypeNorthWestSouthEastResize: - return aura::kCursorNorthWestSouthEastResize; + return ui::kCursorNorthWestSouthEastResize; case WebCursorInfo::TypeColumnResize: - return aura::kCursorColumnResize; + return ui::kCursorColumnResize; case WebCursorInfo::TypeRowResize: - return aura::kCursorRowResize; + return ui::kCursorRowResize; case WebCursorInfo::TypeMiddlePanning: - return aura::kCursorMiddlePanning; + return ui::kCursorMiddlePanning; case WebCursorInfo::TypeEastPanning: - return aura::kCursorEastPanning; + return ui::kCursorEastPanning; case WebCursorInfo::TypeNorthPanning: - return aura::kCursorNorthPanning; + return ui::kCursorNorthPanning; case WebCursorInfo::TypeNorthEastPanning: - return aura::kCursorNorthEastPanning; + return ui::kCursorNorthEastPanning; case WebCursorInfo::TypeNorthWestPanning: - return aura::kCursorNorthWestPanning; + return ui::kCursorNorthWestPanning; case WebCursorInfo::TypeSouthPanning: - return aura::kCursorSouthPanning; + return ui::kCursorSouthPanning; case WebCursorInfo::TypeSouthEastPanning: - return aura::kCursorSouthEastPanning; + return ui::kCursorSouthEastPanning; case WebCursorInfo::TypeSouthWestPanning: - return aura::kCursorSouthWestPanning; + return ui::kCursorSouthWestPanning; case WebCursorInfo::TypeWestPanning: - return aura::kCursorWestPanning; + return ui::kCursorWestPanning; case WebCursorInfo::TypeMove: - return aura::kCursorMove; + return ui::kCursorMove; case WebCursorInfo::TypeVerticalText: - return aura::kCursorVerticalText; + return ui::kCursorVerticalText; case WebCursorInfo::TypeCell: - return aura::kCursorCell; + return ui::kCursorCell; case WebCursorInfo::TypeContextMenu: - return aura::kCursorContextMenu; + return ui::kCursorContextMenu; case WebCursorInfo::TypeAlias: - return aura::kCursorAlias; + return ui::kCursorAlias; case WebCursorInfo::TypeProgress: - return aura::kCursorProgress; + return ui::kCursorProgress; case WebCursorInfo::TypeNoDrop: - return aura::kCursorNoDrop; + return ui::kCursorNoDrop; case WebCursorInfo::TypeCopy: - return aura::kCursorCopy; + return ui::kCursorCopy; case WebCursorInfo::TypeNone: - return aura::kCursorNone; + return ui::kCursorNone; case WebCursorInfo::TypeNotAllowed: - return aura::kCursorNotAllowed; + return ui::kCursorNotAllowed; case WebCursorInfo::TypeZoomIn: - return aura::kCursorZoomIn; + return ui::kCursorZoomIn; case WebCursorInfo::TypeZoomOut: - return aura::kCursorZoomOut; + return ui::kCursorZoomOut; case WebCursorInfo::TypeGrab: - return aura::kCursorGrab; + return ui::kCursorGrab; case WebCursorInfo::TypeGrabbing: - return aura::kCursorGrabbing; - case WebCursorInfo::TypeCustom: - return aura::kCursorCustom; + return ui::kCursorGrabbing; + case WebCursorInfo::TypeCustom: { + ui::Cursor cursor; + cursor.SetPlatformCursor(GetPlatformCursor()); + return cursor; + } default: NOTREACHED(); return gfx::kNullCursor; } } - -void WebCursor::InitPlatformData() { -} - -bool WebCursor::SerializePlatformData(Pickle* pickle) const { - return true; -} - -bool WebCursor::DeserializePlatformData(PickleIterator* iter) { - return true; -} - -bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { - return true; -} - -void WebCursor::CleanupPlatformData() { -} - -void WebCursor::CopyPlatformData(const WebCursor& other) { -} diff --git a/webkit/glue/webcursor_aurawin.cc b/webkit/glue/webcursor_aurawin.cc new file mode 100644 index 0000000..b47ba51 --- /dev/null +++ b/webkit/glue/webcursor_aurawin.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2012 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 "webkit/glue/webcursor.h" + +#include <windows.h> + +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" + +const ui::PlatformCursor WebCursor::GetPlatformCursor() { + // TODO(winguru): + return LoadCursor(NULL, IDC_ARROW); +} + +void WebCursor::InitPlatformData() { +} + +bool WebCursor::SerializePlatformData(Pickle* pickle) const { + return true; +} + +bool WebCursor::DeserializePlatformData(PickleIterator* iter) { + return true; +} + +bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { + return true; +} + +void WebCursor::CleanupPlatformData() { +} + +void WebCursor::CopyPlatformData(const WebCursor& other) { +} diff --git a/webkit/glue/webcursor_aurax11.cc b/webkit/glue/webcursor_aurax11.cc new file mode 100644 index 0000000..fe221e2 --- /dev/null +++ b/webkit/glue/webcursor_aurax11.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2012 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 "webkit/glue/webcursor.h" + +#include <X11/Xcursor/Xcursor.h> +#include <X11/Xlib.h> +#include <X11/cursorfont.h> + +#include "base/logging.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" +#include "third_party/skia/include/core/SkUnPreMultiply.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/x/x11_util.h" + +const ui::PlatformCursor WebCursor::GetPlatformCursor() { + if (platform_cursor_) + return platform_cursor_; + + XcursorImage* image = + XcursorImageCreate(custom_size_.width(), custom_size_.height()); + image->xhot = hotspot_.x(); + image->yhot = hotspot_.y(); + uint32* pixels = image->pixels; + + if (custom_size_.width() && custom_size_.height()) { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, + custom_size_.width(), custom_size_.height()); + bitmap.allocPixels(); + memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size()); + + bitmap.lockPixels(); + int height = bitmap.height(), width = bitmap.width(); + for (int y = 0, i = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + uint32 pixel = bitmap.getAddr32(0, y)[x]; + int alpha = SkColorGetA(pixel); + if (alpha != 0 && alpha != 255) + pixels[i] = SkUnPreMultiply::PMColorToColor(pixel); + else + pixels[i] = pixel; + ++i; + } + } + bitmap.unlockPixels(); + } + + platform_cursor_ = ui::CreateReffedCustomXCursor(image); + return platform_cursor_; +} + +void WebCursor::InitPlatformData() { + platform_cursor_ = 0; +} + +bool WebCursor::SerializePlatformData(Pickle* pickle) const { + return true; +} + +bool WebCursor::DeserializePlatformData(PickleIterator* iter) { + return true; +} + +bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const { + return true; +} + +void WebCursor::CleanupPlatformData() { + if (platform_cursor_) { + ui::UnrefCustomXCursor(platform_cursor_); + platform_cursor_ = 0; + } +} + +void WebCursor::CopyPlatformData(const WebCursor& other) { + if (platform_cursor_) + ui::UnrefCustomXCursor(platform_cursor_); + platform_cursor_ = other.platform_cursor_; + if (platform_cursor_) + ui::RefCustomXCursor(platform_cursor_); +} diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 987eb2c..8bebf2a 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -401,6 +401,8 @@ 'webcursor.h', 'webcursor_android.cc', 'webcursor_aura.cc', + 'webcursor_aurawin.cc', + 'webcursor_aurax11.cc', 'webcursor_gtk.cc', 'webcursor_gtk_data.h', 'webcursor_mac.mm', @@ -499,6 +501,11 @@ 'webcursor_win.cc', ], }], + ['use_aura==1 and use_x11==1', { + 'link_settings': { + 'libraries': [ '-lXcursor', ], + }, + }], ['OS!="mac"', { 'sources/': [['exclude', '_mac\\.(cc|mm)$']], 'sources!': [ |