summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 20:43:10 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 20:43:10 +0000
commitf54bd1779f114be16dd4b4007f1ed68c2041cc68 (patch)
treec26379932e05757286184a6a15c8021231987488 /ui/aura
parentce4f353e191b1aa40d48b7ee6f39365ade3db507 (diff)
downloadchromium_src-f54bd1779f114be16dd4b4007f1ed68c2041cc68.zip
chromium_src-f54bd1779f114be16dd4b4007f1ed68c2041cc68.tar.gz
chromium_src-f54bd1779f114be16dd4b4007f1ed68c2041cc68.tar.bz2
Aura: Adds custom cursors for drag and drop (second attempt:
first attempt reverted due to build break: http://codereview.chromium.org/10316019 ) BUG=121135 TEST=none Review URL: https://chromiumcodereview.appspot.com/10378079 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136653 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/aura.gyp35
-rw-r--r--ui/aura/root_window_host_linux.cc55
-rw-r--r--ui/aura/root_window_host_linux.h3
-rw-r--r--ui/aura/test/test_aura_initializer.cc31
-rw-r--r--ui/aura/test/test_aura_initializer.h28
5 files changed, 151 insertions, 1 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 00e8054..2edd11c 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -19,6 +19,8 @@
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
'../ui.gyp:ui_resources',
+ '../ui.gyp:ui_resources_2x',
+ '../ui.gyp:ui_resources_standard',
],
'defines': [
'AURA_IMPLEMENTATION',
@@ -130,6 +132,7 @@
'../../testing/gtest.gyp:gtest',
'../ui.gyp:ui',
'aura',
+ 'test_support_aura_pak',
],
'include_dirs': [
'..',
@@ -143,6 +146,8 @@
'test/event_generator.h',
'test/test_activation_client.cc',
'test/test_activation_client.h',
+ 'test/test_aura_initializer.cc',
+ 'test/test_aura_initializer.h',
'test/test_event_filter.cc',
'test/test_event_filter.h',
'test/test_screen.cc',
@@ -156,6 +161,36 @@
],
},
{
+ # We build a minimal set of resources required for test_support_aura.
+ 'target_name': 'test_support_aura_pak',
+ 'type': 'none',
+ 'dependencies': [
+ '<(DEPTH)/ui/ui.gyp:ui_resources_standard',
+ ],
+ 'variables': {
+ 'repack_path': '<(DEPTH)/tools/grit/grit/format/repack.py',
+ },
+ 'actions': [
+ {
+ 'action_name': 'repack_test_support_aura_pack',
+ 'variables': {
+ 'pak_inputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources_standard/ui_resources_standard.pak',
+ ],
+ },
+ 'inputs': [
+ '<(repack_path)',
+ '<@(pak_inputs)',
+ ],
+ 'outputs': [
+ '<(PRODUCT_DIR)/test_support_aura_resources.pak',
+ ],
+ 'action': ['python', '<(repack_path)', '<@(_outputs)',
+ '<@(pak_inputs)'],
+ },
+ ],
+ },
+ {
'target_name': 'aura_demo',
'type': 'executable',
'dependencies': [
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index 83ca3ee..d9b9cd3 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -5,6 +5,7 @@
#include "ui/aura/root_window_host_linux.h"
#include <X11/Xatom.h>
+#include <X11/Xcursor/Xcursor.h>
#include <X11/cursorfont.h>
#include <X11/extensions/XInput2.h>
#include <X11/extensions/Xfixes.h>
@@ -14,6 +15,8 @@
#include "base/message_pump_x.h"
#include "base/stl_util.h"
#include "base/stringprintf.h"
+#include "grit/ui_resources_standard.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/aura/client/user_gesture_client.h"
#include "ui/aura/dispatcher_linux.h"
#include "ui/aura/env.h"
@@ -21,10 +24,12 @@
#include "ui/aura/root_window.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/keycodes/keyboard_codes.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/view_prop.h"
#include "ui/base/x/x11_util.h"
#include "ui/compositor/layer.h"
+#include "ui/gfx/image/image.h"
using std::max;
using std::min;
@@ -292,6 +297,51 @@ const char* kAtomList[] = {
} // namespace
+// A utility class that provides X Cursor for NativeCursors for which we have
+// image resources.
+class RootWindowHostLinux::ImageCursors {
+ public:
+ ImageCursors() {
+ LoadImageCursor(ui::kCursorNoDrop, IDR_AURA_CURSOR_NO_DROP);
+ LoadImageCursor(ui::kCursorCopy, IDR_AURA_CURSOR_COPY);
+ // TODO (varunjain): add more cursors once we have assets.
+ }
+
+ ~ImageCursors() {
+ std::map<int, Cursor>::const_iterator it;
+ for (it = cursors_.begin(); it != cursors_.end(); ++it)
+ ui::UnrefCustomXCursor(it->second);
+ }
+
+ // Returns true if we have an image resource loaded for the |native_cursor|.
+ bool IsImageCursor(gfx::NativeCursor native_cursor) {
+ return cursors_.find(native_cursor.native_type()) != cursors_.end();
+ }
+
+ // Gets the X Cursor corresponding to the |native_cursor|.
+ ::Cursor ImageCursorFromNative(gfx::NativeCursor native_cursor) {
+ DCHECK(cursors_.find(native_cursor.native_type()) != cursors_.end());
+ return cursors_[native_cursor.native_type()];
+ }
+
+ private:
+ // Creates an X Cursor from an image resource and puts it in the cursor map.
+ void LoadImageCursor(int id, int resource_id) {
+ const SkBitmap* bitmap =
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ resource_id).ToSkBitmap();
+
+ XcursorImage* image = ui::SkBitmapToXcursorImage(bitmap, gfx::Point(0, 0));
+ cursors_[id] = ui::CreateReffedCustomXCursor(image);
+ // |bitmap| is owned by the resource bundle. So we do not need to free it.
+ }
+
+ // A map to hold all image cursors. It maps the cursor ID to the X Cursor.
+ std::map<int, Cursor> cursors_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageCursors);
+};
+
RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
: root_window_(NULL),
xdisplay_(base::MessagePumpX::GetDefaultXDisplay()),
@@ -301,7 +351,8 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
cursor_shown_(true),
bounds_(bounds),
focus_when_shown_(false),
- pointer_barriers_(NULL) {
+ pointer_barriers_(NULL),
+ image_cursors_(new ImageCursors) {
XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa));
swa.background_pixmap = None;
@@ -794,6 +845,8 @@ bool RootWindowHostLinux::IsWindowManagerPresent() {
void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
::Cursor xcursor =
+ image_cursors_->IsImageCursor(cursor) ?
+ image_cursors_->ImageCursorFromNative(cursor) :
cursor == ui::kCursorNone ?
invisible_cursor_ :
cursor == ui::kCursorCustom ?
diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h
index ae435e9..34484e4 100644
--- a/ui/aura/root_window_host_linux.h
+++ b/ui/aura/root_window_host_linux.h
@@ -101,6 +101,9 @@ class RootWindowHostLinux : public RootWindowHost,
scoped_ptr<ui::ViewProp> prop_;
+ class ImageCursors;
+ scoped_ptr<ImageCursors> image_cursors_;
+
DISALLOW_COPY_AND_ASSIGN(RootWindowHostLinux);
};
diff --git a/ui/aura/test/test_aura_initializer.cc b/ui/aura/test/test_aura_initializer.cc
new file mode 100644
index 0000000..f586d65
--- /dev/null
+++ b/ui/aura/test/test_aura_initializer.cc
@@ -0,0 +1,31 @@
+// 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 "ui/aura/test/test_aura_initializer.h"
+
+#include "base/base_paths.h"
+#include "base/path_service.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace aura {
+namespace test {
+
+TestAuraInitializer::TestAuraInitializer() {
+#if defined(OS_LINUX)
+ FilePath pak_file;
+ PathService::Get(base::DIR_MODULE, &pak_file);
+ pak_file = pak_file.Append(FILE_PATH_LITERAL(
+ "test_support_aura_resources.pak"));
+ ui::ResourceBundle::InitSharedInstanceWithPakFile(pak_file);
+#endif
+}
+
+TestAuraInitializer::~TestAuraInitializer() {
+#if defined(OS_LINUX)
+ ui::ResourceBundle::CleanupSharedInstance();
+#endif
+}
+
+} // namespace test
+} // namespace aura
diff --git a/ui/aura/test/test_aura_initializer.h b/ui/aura/test/test_aura_initializer.h
new file mode 100644
index 0000000..cb276ce
--- /dev/null
+++ b/ui/aura/test/test_aura_initializer.h
@@ -0,0 +1,28 @@
+// 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.
+
+#ifndef UI_AURA_TEST_TEST_AURA_INITIALIZER_H_
+#define UI_AURA_TEST_TEST_AURA_INITIALIZER_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+namespace aura {
+namespace test {
+
+// Initializes various objects needed to run unit tests that use aura::*
+// objects.
+class TestAuraInitializer {
+ public:
+ TestAuraInitializer();
+ virtual ~TestAuraInitializer();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestAuraInitializer);
+};
+
+} // namespace test
+} // namespace aura
+
+#endif // UI_AURA_TEST_TEST_AURA_INITIALIZER_H_