| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/cursors/webcursor.h" | 5 #include "webkit/common/cursors/webcursor.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 int hotspot_y) { | 131 int hotspot_y) { |
| 132 if (base::mac::IsOSLionOrLater()) { | 132 if (base::mac::IsOSLionOrLater()) { |
| 133 NSCursor* cursor = [CrCoreCursor cursorWithType:type]; | 133 NSCursor* cursor = [CrCoreCursor cursorWithType:type]; |
| 134 if (cursor) | 134 if (cursor) |
| 135 return cursor; | 135 return cursor; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return LoadCursor(resource_id, hotspot_x, hotspot_y); | 138 return LoadCursor(resource_id, hotspot_x, hotspot_y); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // TODO(avi): When Skia becomes default, fold this function into the remaining | |
| 142 // caller, InitFromCursor(). | |
| 143 CGImageRef CreateCGImageFromCustomData(const std::vector<char>& custom_data, | |
| 144 const gfx::Size& custom_size) { | |
| 145 // If the data is missing, leave the backing transparent. | |
| 146 void* data = NULL; | |
| 147 if (!custom_data.empty()) { | |
| 148 // This is safe since we're not going to draw into the context we're | |
| 149 // creating. | |
| 150 data = const_cast<char*>(&custom_data[0]); | |
| 151 } | |
| 152 | |
| 153 // If the size is empty, use a 1x1 transparent image. | |
| 154 gfx::Size size = custom_size; | |
| 155 if (size.IsEmpty()) { | |
| 156 size.SetSize(1, 1); | |
| 157 data = NULL; | |
| 158 } | |
| 159 | |
| 160 base::ScopedCFTypeRef<CGColorSpaceRef> cg_color( | |
| 161 CGColorSpaceCreateDeviceRGB()); | |
| 162 // The settings here match SetCustomData() below; keep in sync. | |
| 163 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate( | |
| 164 data, | |
| 165 size.width(), | |
| 166 size.height(), | |
| 167 8, | |
| 168 size.width() * 4, | |
| 169 cg_color.get(), | |
| 170 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big)); | |
| 171 return CGBitmapContextCreateImage(context.get()); | |
| 172 } | |
| 173 | |
| 174 NSCursor* CreateCustomCursor(const std::vector<char>& custom_data, | 141 NSCursor* CreateCustomCursor(const std::vector<char>& custom_data, |
| 175 const gfx::Size& custom_size, | 142 const gfx::Size& custom_size, |
| 176 float custom_scale, | 143 float custom_scale, |
| 177 const gfx::Point& hotspot) { | 144 const gfx::Point& hotspot) { |
| 178 // If the data is missing, leave the backing transparent. | 145 // If the data is missing, leave the backing transparent. |
| 179 void* data = NULL; | 146 void* data = NULL; |
| 180 size_t data_size = 0; | 147 size_t data_size = 0; |
| 181 if (!custom_data.empty()) { | 148 if (!custom_data.empty()) { |
| 182 // This is safe since we're not going to draw into the context we're | 149 // This is safe since we're not going to draw into the context we're |
| 183 // creating. | 150 // creating. |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 return true; | 386 return true; |
| 420 } | 387 } |
| 421 | 388 |
| 422 void WebCursor::CleanupPlatformData() { | 389 void WebCursor::CleanupPlatformData() { |
| 423 return; | 390 return; |
| 424 } | 391 } |
| 425 | 392 |
| 426 void WebCursor::CopyPlatformData(const WebCursor& other) { | 393 void WebCursor::CopyPlatformData(const WebCursor& other) { |
| 427 return; | 394 return; |
| 428 } | 395 } |
| OLD | NEW |