OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "ui/base/cursor/cursor_loader_ozone.h" |
| 6 |
| 7 #include "ui/base/cursor/cursor.h" |
| 8 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/gfx/image/image_skia.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Creates a 1x1 cursor which will be fully transparent. |
| 16 SkBitmap CreateInvisibleCursor() { |
| 17 SkBitmap cursor; |
| 18 cursor.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 19 cursor.allocPixels(); |
| 20 |
| 21 cursor.lockPixels(); |
| 22 cursor.eraseARGB(0, 0, 0, 0); |
| 23 cursor.unlockPixels(); |
| 24 |
| 25 return cursor; |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 CursorLoaderOzone::CursorLoaderOzone() |
| 31 : invisible_cursor_(CreateInvisibleCursor()) {} |
| 32 |
| 33 CursorLoaderOzone::~CursorLoaderOzone() {} |
| 34 |
| 35 void CursorLoaderOzone::LoadImageCursor(int id, |
| 36 int resource_id, |
| 37 const gfx::Point& hot) { |
| 38 cursors_[id] = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 39 resource_id); |
| 40 } |
| 41 |
| 42 void CursorLoaderOzone::LoadAnimatedCursor(int id, |
| 43 int resource_id, |
| 44 const gfx::Point& hot, |
| 45 int frame_delay_ms) { |
| 46 // TODO(dnicoara) Add support: crbug.com/343245 |
| 47 NOTIMPLEMENTED(); |
| 48 } |
| 49 |
| 50 void CursorLoaderOzone::UnloadAll() { |
| 51 cursors_.clear(); |
| 52 } |
| 53 |
| 54 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { |
| 55 if (cursors_.find(cursor->native_type()) != cursors_.end()) { |
| 56 const gfx::ImageSkiaRep& image_rep = |
| 57 cursors_[cursor->native_type()]->GetRepresentation( |
| 58 display().device_scale_factor()); |
| 59 |
| 60 cursor->SetPlatformCursor(&image_rep.sk_bitmap()); |
| 61 } else if (*cursor == kCursorNone) { |
| 62 cursor->SetPlatformCursor(&invisible_cursor_); |
| 63 } else if (*cursor == kCursorCustom) { |
| 64 // TODO(dnicoara) Add support for custom cursors: crbug.com/343155 |
| 65 cursor->SetPlatformCursor(cursor->platform()); |
| 66 } else { |
| 67 const gfx::ImageSkiaRep& image_rep = |
| 68 cursors_[kCursorPointer]->GetRepresentation( |
| 69 display().device_scale_factor()); |
| 70 |
| 71 cursor->SetPlatformCursor(&image_rep.sk_bitmap()); |
| 72 } |
| 73 } |
| 74 |
| 75 CursorLoader* CursorLoader::Create() { |
| 76 return new CursorLoaderOzone(); |
| 77 } |
| 78 |
| 79 } // namespace ui |
OLD | NEW |