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

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: x custom cursor cache 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 XcursorImage* image =
28 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_ = ui::CreateReffedCustomXCursor(image);
49 return platform_cursor_;
50 }
51
52 void WebCursor::InitPlatformData() {
53 platform_cursor_ = 0;
54 }
55
56 bool WebCursor::SerializePlatformData(Pickle* pickle) const {
57 return true;
58 }
59
60 bool WebCursor::DeserializePlatformData(const Pickle* pickle, void** iter) {
61 return true;
62 }
63
64 bool WebCursor::IsPlatformDataEqual(const WebCursor& other) const {
65 return true;
66 }
67
68 void WebCursor::CleanupPlatformData() {
69 if (platform_cursor_) {
70 ui::UnrefCustomXCursor(platform_cursor_);
71 platform_cursor_ = 0;
72 }
73 }
74
75 void WebCursor::CopyPlatformData(const WebCursor& other) {
76 if (platform_cursor_)
77 ui::UnrefCustomXCursor(platform_cursor_);
78 platform_cursor_ = other.platform_cursor_;
79 if (platform_cursor_)
80 ui::RefCustomXCursor(platform_cursor_);
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698