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 #include "ui/ozone/public/cursor_factory_ozone.h" 11 12 namespace ui { 13 14 CursorLoaderOzone::CursorLoaderOzone() {} 15 16 CursorLoaderOzone::~CursorLoaderOzone() {} 17 18 void CursorLoaderOzone::LoadImageCursor(int id, 19 int resource_id, 20 const gfx::Point& hot) { 21 const gfx::ImageSkia* image = 22 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 23 const gfx::ImageSkiaRep& image_rep = 24 image->GetRepresentation(scale()); 25 SkBitmap bitmap = image_rep.sk_bitmap(); 26 cursors_[id] = 27 CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap, hot); 28 } 29 30 void CursorLoaderOzone::LoadAnimatedCursor(int id, 31 int resource_id, 32 const gfx::Point& hot, 33 int frame_delay_ms) { 34 // TODO(dnicoara) Add support: crbug.com/343245 35 NOTIMPLEMENTED(); 36 } 37 38 void CursorLoaderOzone::UnloadAll() { 39 for (ImageCursorMap::const_iterator it = cursors_.begin(); 40 it != cursors_.end(); 41 ++it) 42 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second); 43 cursors_.clear(); 44 } 45 46 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { 47 int native_type = cursor->native_type(); 48 PlatformCursor platform; 49 50 if (cursors_.count(native_type)) { 51 // An image cursor is loaded for this type. 52 platform = cursors_[native_type]; 53 } else if (native_type == kCursorCustom) { 54 // The platform cursor was already set via WebCursor::GetPlatformCursor. 55 platform = cursor->platform(); 56 } else { 57 // Use default cursor of this type. 58 platform = CursorFactoryOzone::GetInstance()->GetDefaultCursor(native_type); 59 } 60 61 cursor->SetPlatformCursor(platform); 62 } 63 64 CursorLoader* CursorLoader::Create() { 65 return new CursorLoaderOzone(); 66 } 67 68 } // namespace ui 69