Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: webkit/glue/webcursor_aurax11.cc

Issue 9463003: aura-x11: Add custom web cursor support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "webkit/glue/webcursor.h"
6
7 #include <X11/Xlib.h>
8 #include <X11/Xcursor/Xcursor.h>
9 #include <X11/cursorfont.h>
10
11 #include "base/logging.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
13 #include "third_party/skia/include/core/SkUnPreMultiply.h"
14 #include "ui/aura/cursor.h"
15 #include "ui/base/x/x11_util.h"
16
17 const gfx::PlatformCursor& WebCursor::GetPlatformCursor() {
18 if (platform_cursor_)
19 return platform_cursor_;
20
21 SkBitmap bitmap;
22 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
23 custom_size_.width(), custom_size_.height());
24 bitmap.allocPixels();
25 memcpy(bitmap.getAddr32(0, 0), custom_data_.data(), custom_data_.size());
26
27 Display* xdisplay = ui::GetXDisplay();
28 image_ = XcursorImageCreate(custom_size_.width(), custom_size_.height());
29 image_->xhot = hotspot_.x();
30 image_->yhot = hotspot_.y();
31 uint32* pixels = image_->pixels;
32
33 bitmap.lockPixels();
34 int height = bitmap.height(), width = bitmap.width();
35 for (int y = 0, i = 0; y < height; y++) {
36 for (int x = 0; x < width; x++) {
37 uint32 pixel = bitmap.getAddr32(0, y)[x];
38 int alpha = SkColorGetA(pixel);
39 if (alpha != 0 && alpha != 255)
40 pixels[i] = SkUnPreMultiply::PMColorToColor(pixel);
41 else
42 pixels[i] = pixel;
43 ++i;
44 }
45 }
46 bitmap.unlockPixels();
47
48 platform_cursor_ = XcursorImageLoadCursor(xdisplay, image_);
49 return platform_cursor_;
50 }
51
52 void WebCursor::InitPlatformData() {
53 platform_cursor_ = 0;
54 image_ = NULL;
55 }
56
57 bool WebCursor::SerializePlatformData(Pickle* pickle) const {
58 return true;
59 }
60
61 bool WebCursor::DeserializePlatformData(const Pickle* pickle, void** iter) {
62 return true;
63 }
64
65 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
66 return true;
67 }
68
69 void WebCursor::CleanupPlatformData() {
70 if (platform_cursor_) {
71 XFreeCursor(ui::GetXDisplay(), platform_cursor_);
72 platform_cursor_ = 0;
73 }
74
75 if (image_) {
76 XcursorImageDestroy(image_);
77 image_ = NULL;
78 }
79 }
80
81 void WebCursor::CopyPlatformData(const WebCursor& other) {
82 platform_cursor_ = other.platform_cursor_;
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698